flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > DOS > [CALL vs JMP] ret not working

Author
Thread Post new topic Reply to topic
theguy



Joined: 22 Jan 2015
Posts: 10
[CALL vs JMP] ret not working
hello again, here's working code that has no problem printing char 'x' to the screen.


Code:

org 100h

mov al'x'
jmp label_test

label_test:
mov ah0x0e
int 0x10

Looop:
jmp Looop




But if i add a ret to label_test, trying to use it like a function with the code below.


Code:

org 100h

mov al'x'
jmp label_test

mov al'y'
jmp label_test

label_test:
mov ah0x0e
int 0x10
ret

Looop:
jmp Looop




It opens and closes quickly If i run the exe, this lets me know that it's not going into the infinite loop properly. so i ran it using the command prompt of ms-dos and it shows it's only printing the x?

I don't get why all the examples i use online that are suppose to help me learn this stuff, all fail to function when i try them.
Post 23 Jan 2015, 05:12
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
Re: ret not working
Hello.

theguy wrote:

But if i add a ret to label_test, trying to use it like a function with the code below.

- snip -

It opens and closes quickly If i run the exe, this lets me know that it's not going into the infinite loop properly. so i ran it using the command prompt of ms-dos and it shows it's only printing the x?


This is because DOS place the instruction of an "int 20h" at the top of the PSP and it push a zero word to the stack just before it let the COM-program execute. if we do not corrupt the stack and the code segment and if we execute at last the "ret" instruction, then the cpu return to the address of zero and continue executing the instruction of the "int 20h" inside of the PSP for terminating our programm.

And for calling a subroutine we can use the call instruction. The call instruction push its return address to the stack and if we execute a ret intstruction, then the cpu pop the return address from the stack and return to the caller for executing the next instruction.


Code:

org 100h

mov al'x'
call label_test

mov al'y'
call label_test

Looop:
jmp Looop
;-------------
; Subroutines
;-------------
label_test:
mov ah0x0e
int 0x10
ret


Post 23 Jan 2015, 07:09
View user's profile Send private message Send e-mail Reply with quote
theguy



Joined: 22 Jan 2015
Posts: 10
That works! Very Happy, thanks ill have to look into this more closely to fully understand it, is there any good sources out there that could teach me by example, using only dos not windows forms.
Post 23 Jan 2015, 07:16
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
theguy,

There are tons of open-source assembly language DOS programs available, Google is your friend (though most of them are MASM/TASM/nasm). You may as well contrive simple problem and try to make solution, community here will help if you show some efforts. Just ask relevant questions. Wink
Post 23 Jan 2015, 09:49
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.