Re: Reviving SP question


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

Re: Reviving SP question



At 08:33 AM 8/9/97 -0400, you wrote:
>>I previously wrote to this list about the SP register.  I have one little
>>question left.  Since SP is a 16 bit register and the stack is built from
>>$FFFF, then a push and a pop looks something like this (I could be wrong,
>>so correct me if I am):
>>
>>Push:
>>  SP=PC
>>  DEC SP
>>  DEC SP
>>
>>Pop:
>>  INC SP
>>  INC SP
>>  PC=SP
>>
>>I have a couple questions about the above "code":
>>Do I need 1 or 2 INCs/DECs?
>>Should the DEC(s) in the Push code come before and the INC(s) in the Pop
>>come after or are both in the correct position?
>
>You don't need this code at all.  You seem to be trying to save the Program
>counter on the stack and then restore it later.  That's what CALL and RET
>do.

Its pseudocode.  This means its an EXAMPLE only, NOT actual code.

>CALL $E94F will put $4F at SP, decrement SP and put $E9 at the new SP (old
>SP-1).  It will then decrement SP again.  RET will load PC with $E94F.

Don't you mean that PC will be stored/retrieved on the stack?  You would be
putting the calc in an infinite loop if it executed what you said it should
do.

>To save the HL register on the stack, just PUSH HL.  To retrieve it, POP HL.
>This does the same type of thing.  L is at SP and H is at SP-1.  If you
>REALLY want to emulate the built-in instructions without using PUSH, POP,
>CALL or RET, you have to:
>
>1.  Save the low byte of the 16-bit register at the location pointed to by
>the current SP.
>2. Decrement SP
>3.  Save the high byte of the 16-bit register at the location pointed to by
>the current SP (this is the original SP -1)
>4.  Decrement SP again.


                 Thomas J. Hruska -- thruska@tir.com
Shining Light Productions -- "Meeting the needs of fellow programmers"
         http://www.geocities.com/SiliconValley/Heights/8504
                    http://shinelight.home.ml.org


References: