Ret function

Thread Starter

salohcin

Joined May 15, 2011
6
i'm currently doing a project on 8051
the project has 6 different states and conditions so i have to use the RET function after call and excuting Delay, how can i do it?

Example:
Start:
(code)
jmp State1

State1:
(all the code needed)
jmp DELAY1
jmp State2

(codes)

DELAY:
(time delay code)
RET( after here it auto jump back to start of program thus state1 did no go to state2 i know i have to use push and pop instruction but i have no idea how to can any1 show it to me?
 

hgmjr

Joined Jan 28, 2005
9,027
A RET statement is used to return from a CALL to a subroutine. If you use the RET statement in any other context the program is going to do some very strange and unpredictable things since RET assumes that the point in the program to which it should return is located on the STACK. Since the CALL statement was not executed then the program will load the program counter with a value it pulls from the STACK and begin executing code. It is highly unlikely that the program counter value it retrieves from the STACK will be the point in your program to which you wanted to return.

hgmjr
 
Top