Re: A86: calling and returning
[Prev][Next][Index][Thread]
Re: A86: calling and returning
Thanks Jonah
----- Original Message -----
From: <ComAsYuAre@aol.com>
To: <assembly-86@lists.ticalc.org>
Sent: Sunday, December 05, 1999 9:44 PM
Subject: Re: A86: calling and returning
In a message dated 12/5/99 22:17:02 Eastern Standard Time, brent@calc.org
writes:
> but, I haven't pushed anything.. so what do I do? is there something about
> the pc counter?
Call will push the address of the next opcode (command) onto the stack
before
branching somewhere. Likewise, ret will pop the last address off the stack
and go there. For example, this will essentially do the exact same thing as
call and ret:
;for call
ld hl,next_byte
push hl ;push next address onto stack
jp subroutine ;branch to subroutine
next_byte:
;for ret
pop hl ;pop address of stack
jp (hl) ;jump to address
So, if you wanted to jp the the address pointed to by bc, for example, you
could do the following:
push bc
ret
Or if you wanted to quit from a subroutine (like you were talking about),
you
could do this:
call subroutine
;...more code
subroutine:
pop hl ;pop calling address off stack
ret ;return to os
----
Jonah Cohen
<ComAsYuAre@aol.com>
http://linux.hypnotic.org/~jonah/
References: