PDA

View Full Version : x86 assembly



Shadow
02-06-2003, 01:51 AM
For a true first program, does this look ok?
; ------------------------
; 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
ENDI 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.

Carlos
02-06-2003, 06:02 AM
It's ok, you could just optimize a little bit.
Instead of :


mov dx, OFFSET MessageA
mov ax, SEG MessageA
mov ds, ax


rather use



mov ax, @data
mov ds, ax
lea dx, ds:[MessageA]


ASM is cool! Have fun!

Shadow
02-06-2003, 10:44 AM
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.

Shadow
02-08-2003, 11:59 PM
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.

dizolve
02-16-2003, 11:59 PM
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

Waldo2k2
02-17-2003, 01:11 AM
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.

Shadow
02-17-2003, 02:09 PM
> What if he or I were coding for unix?
I am using MS DOS 6.22 myself.

Waldo2k2
02-17-2003, 02:21 PM
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.

Shadow
02-17-2003, 02:29 PM
> 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.

Carlos
02-18-2003, 02:29 AM
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!