Re: A83: PUSH/POPs...


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

Re: A83: PUSH/POPs...







"Thomas J. Hruska" wrote:
> 
> As I write this, I am looking at the Z80 Microprocessor Instruction Set
> Summary by Jonathon Bowen.  Based on the PUSH/POP section, it says:
> 
> POP xx       xx=(SP)+
> PUSH xx      -(SP)=xx
> 
> Where SP is the Stack Pointer register and xx is IX, IY, AF, BC, DE, or HL.
>  I have two questions:
> 
> 1)  Upon a PUSH, is the Stack Pointer decremented BEFORE or AFTER the
> register is stored on the stack?

push decrements first, and stores then. therefore is the minus before
parantesis.
pop increments after.
it is very simple to see why too.
take push. you want to store something and make the SP point to that. you
already have somthing stored on the stack that the pointer points to..  ofcourse
you first decrements the pointer to make room for the new data and puts it on
that memory location. if not, you would first overwrite what was previously
point, and then let the pointer point to a memroyaddress that does not contain
the data.

> 
> 2)  How are the registers stored on a PUSH?  Are they stored:
> 
> FORWARD?
> --------
> $FD00  00 00 00 00 00 00 00 00
> $FD08  00 00 00 00 00 00 00 00
> ...
> $FFF0  00 00 00 AF AF BC HL ED
> 
> OR BACKWARD?
> ------------
> $FE00  00 00 00 00 00 00 00 00
> $FE10  00 00 00 00 00 00 00 00
> ...
> $FFF0  00 00 00 FA FA CB LH ED
> 

None of the above.

it is stored like this:
take AF. AF is a 16 bit number, two bytes, the A byte and the F byte.
A is most significant. and the z80 stores 16 bit numbers in "reverse byte order"
(like Intel x86)

therefore, if you store it at $FFFD it will be stored like this:


> $FFF0  00 00 00 00 00 00 FF AA

hl is to 16 bit, h byte and l byte, we push that one too:

> $FFF0  00 00 00 00 LL HH FF AA

and so on. Maybe it was like this you ment, but mistyped above..


about that contest? what is the point of byte push and byte pop? I think that
was quite a pointless competition. and stupid rules too :)
so.. your routines.. you use SP as stack pointer I suppose? or do you use HL? a
different stack for bytes? even more pointless then :) if you use SP, how are
you storing a byte in (SP)

jeje.. 

//Olle


References: