A86: Re: Re: calling and returning


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

A86: Re: Re: calling and returning




thanks.. one more question... before I do pop hl after routine:, did I have
to push hl before I called routine?
----- Original Message -----
From: David Phillips <david@acz.org>
To: <assembly-86@lists.ticalc.org>
Sent: Sunday, December 05, 1999 7:40 PM
Subject: A86: Re: calling and returning



Two ways...

First, restore the stack by poping off junk until you get to where you want
to be.  If you're only one call deep, just need one pop.  You can pop into
any register you don't care about trashing, like HL:

 call routine

routine:
 pop hl
 ret           ; will return to the OS

Other way, use the rom call below:

 call _jforcecmdnochar          ; will return us to the OS wherever we are

Actually, there's another way, and that is to store the stack location when
the program starts:

StackSave = ...      ; somewhere free in ram, like _textShadow or something

 ld hl,0
 add hl,sp                    ; HL = SP
 ld (StackSave),hl        ; ah, I miss 16 bit loads...

....

ReturnToOSNoMatterWhereWeAre:
 ld hl,(StackSave)         ; get the stack pointer back
 ld sp,hl                        ; restore the stack pointer
 ret                               ; back to the OS!!!

> Say I did this:
>
> .....code......
> call label1
> .....morecode.......
> label1:
>  ret
>
>
> how would I make it so that ret would return to the os, instead of back to
> where we called it from?
>
> thanks
>
>
>







References: