Re: A86: ret after call


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

Re: A86: ret after call




>From: Dave <dvanee@dowco.com>
>How can I make the 'ret' command end the asm program if I jumped to it
>from inside a call
>
>ie:
>
>call bob   < (HERE) --------------------------------------------\
>								|
>bob:								|
>	ld a,6							|
>	cp 6							|
>	jp z,exit						|
>	ret							|
>								|
>exit:								|
>	ret	<-- this must END the program, not return to --/
>

Here ya go:

var_saved_SP = GRAPH_MEM ; temporary SP, put it wherever you want.
   ;you'll need to save a word for it.

;*** Initialize Exit ***
; IN: none
;OUT: saves SP in saved_SP for exit
;***********************
Init_Exit:
  POP HL
  LD (var_saved_SP),SP
  PUSH HL
  RET

;*** EXIT ***
; IN: none
;OUT: COMPLETELY exits program
;     Don't worry about stack.
;VAR: Saved_SP
;************
Exit:
  LD HL, (var_Saved_SP)
  LD SP,HL
  cls
  RET

END
Just call init_exit at the begining of your program, then just use:

JP Exit

to exit at any point in the program. It will fix the stack, the only way 
it will mess up is if you POP too much off the stack.

--Retupmoc7

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com