[A83] Re: returning to OS in call routines (example code)


[Prev][Next][Index][Thread]

[A83] Re: returning to OS in call routines (example code)



Pretty much, you just save the stack pointer (sp register) at the beginning 
of the program, then restore it and ret to quit.
Example code for allowing a program to quit from anywhere:

Program_Start:
  ld (quit+1),sp              ;Save Stack Pointer (self modifying code)
  ...

Quit:
  ld sp,0  ;any number works here, it gets overwritten
  ret

Then whenever you need to quit, just jp Quit.
Of course, this won't work with apps since it uses self modifying code.

_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail