flat assembler
Message board for the users of flat assembler.

Index > DOS > Absolute Beginner: Help!!!

Author
Thread Post new topic This topic is locked: you cannot edit posts or make replies.
siryuhan



Joined: 17 Nov 2005
Posts: 1
siryuhan 17 Nov 2005, 21:48
I'm trying to get functions to work. For example, in my hello world program i have

Code:
org 100h

push myInputMessage
call print
int 20h

print:
pop dx
add dx, 2h
mov ah, 9
int 21h
ret
    


but this doesn't do anything! I would greatly appreciate any help. Thanks!
Post 17 Nov 2005, 21:48
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 17 Nov 2005, 22:19
siryuhan,
you see there is a little problem with this,
when you do call,
the caller address is pushed onto the stack, so, when you pop dx, you get the return address back in dx, that is not what you wanted.

mhm, btw you dont have to add 2 to address , unless you want to skip first 2 bytes

Code:
org 100h

mov ax,3 ; set video mode (needed under win xp)
int 10h

push myInputMessage
call print

xor ah,ah ; wait keypress (needed under xp to see text)
int 16h

int 20h

print:
pop ax ; save return address
pop dx ; get parameter
push ax ; save return address
mov ah, 9
int 21h
ret


myInputMessage: db "hello","$"
    


this works
Post 17 Nov 2005, 22:19
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic This topic is locked: you cannot edit posts or make replies.

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.