x86 assembly

This is a discussion on x86 assembly within the A Brief History of Cprogramming.com forums, part of the Community Boards category; For a true first program, does this look ok? Code: ; ------------------------ ; Message.asm ; ; This program will print ...

  1. #1
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    x86 assembly

    For a true first program, does this look ok?
    Code:
    ; ------------------------
    ; Message.asm
    ;
    ; This program will print
    ; 3 messages to the screen
    ; ------------------------
    .MODEL SMALL
    .STACK
    
    .DATA
    MessageA db "This is a text message.",	     13, 10, 13, 10, "$"
    MessageB db "This is another text message.", 13, 10, "$"
    MessageC db "This is yet another message.$"
    
    .CODE
    Main	PROC
    
    	Call Message1
    	Call Message2
    	Call Message3
    	Call Exit
    
    	Message1 PROC
    		mov dx, OFFSET MessageA
    		mov ax, SEG MessageA
    		mov ds, ax
    
    		mov ah, 9
    		int 21h
    	Message1 ENDP
    
    	Message2 PROC
    		mov dx, OFFSET MessageB
    		mov ax, SEG MessageB
    		mov ds, ax
    
    		mov ah, 9
    		int 21h
    	Message2 END
    
    	Message3 PROC
    		mov dx, OFFSET MessageC
    		mov ax, SEG MessageC
    		mov ds, ax
    
    		mov ah, 9
    		int 21h
    	Message3 END
    
    	Exit PROC
    		mov ax, 4c00h
    		int 21h
    	Exit ENDP
    
    Main	ENDP
    END
    I was messing around with functions and positioning text with this program.
    Positioning text isn't as easy as it is in C.

    I'm going to start expanding more upon files, input, and output soon.
    Last edited by Shadow; 02-08-2003 at 11:00 PM.
    The world is waiting. I must leave you now.

  2. #2
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    It's ok, you could just optimize a little bit.
    Instead of :
    Code:
    mov dx, OFFSET MessageA
    mov ax, SEG MessageA
    mov ds, ax
    rather use

    Code:
    mov ax, @data
    mov ds, ax
    lea dx, ds:[MessageA]
    ASM is cool! Have fun!

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Thanks for the input Carlos. I did a little research on you, and you appear to know what you're talking about when it comes to ASM.

    Thanks for the advice.
    The world is waiting. I must leave you now.

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Apparently, because of the WhatKey.exe program I wrote in C programming for DOS which returns the scancode of the key you pressed, the enter/return key's scancode value is 13.

    Is this what the number 13 means which is appended to the end of the DATA strings in my above example?
    What does the number 10 mean? Is that some sort of a "stub" or "tag" or something to ensure that 13(return) gets executed?

    I noticed that 13 doesn't work unless you also have 10.
    The world is waiting. I must leave you now.

  5. #5
    Registered User dizolve's Avatar
    Join Date
    Dec 2002
    Posts
    68
    DOS/Windows uses a combination of two characters to signify a new line...

    ASCII #13 is CR - Carriage Return
    ASCII #10 is LF - Line Feed

  6. #6
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    What if he or I were coding for unix? Would unix choke on 10, or would it ignore it? I know that c/c++ compilers take \n and automatically put in \r\n if the target is Dos based. But since this is assembly, I was curious, I haven't toyed enought with it in the last year or so to remember.
    PHP and XML
    Let's talk about SAX

  7. #7
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > What if he or I were coding for unix?
    I am using MS DOS 6.22 myself.
    The world is waiting. I must leave you now.

  8. #8
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    Originally posted by Shadow
    > What if he or I were coding for unix?
    I am using MS DOS 6.22 myself.
    in my eyes there is no other dos
    and that's ok if you didn't know about the unix thing, i was just curious.
    PHP and XML
    Let's talk about SAX

  9. #9
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > in my eyes there is no other dos
    Yes.

    > and that's ok if you didn't know about the unix thing, i was just curious.
    Alrighty. Yeah, I haven't messed with the thing. Hopefully somebody else can help you.

    Good luck.
    The world is waiting. I must leave you now.

  10. #10
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    If you're doing it in Assembly, you have to take care for OS compatibility yourself (e.g. you should forget "real" mode under Unix-es ).

    Unless you call OS services, assembly language is quite the same in different OS-es.

    Regarding the CR-LF (0Dh, 0Ah) pair - in Unix OS-es only LF (0Ah) is needed, this means newline.

    CR might lead to unpredictable results - haven't tried yet, but probably it behaves differently, depending on the used editor.

    Of course, there are different assemblers for different Unix versions (Linux, FreeBSD) - a quick search with google will provide you some really useful stuff.

    If you're really interested, check this one: http://linuxassembly.org/

    Have fun!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A good tutorial for x86 assembly?
    By cyberfish in forum Tech Board
    Replies: 3
    Last Post: 05-10-2009, 11:56 AM
  2. x86 assembly emulator
    By maxorator in forum Tech Board
    Replies: 5
    Last Post: 12-01-2008, 07:21 AM
  3. Networking in x86 Assembly (try not to laugh at me)
    By sean in forum Networking/Device Communication
    Replies: 6
    Last Post: 12-23-2004, 03:54 AM
  4. Arrays In Inline x86 Assembly
    By saxman in forum C Programming
    Replies: 17
    Last Post: 07-07-2004, 02:38 PM
  5. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 02:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21