[A83] Re: push - pop


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

[A83] Re: push - pop




>At 20:14 2001-12-15, you wrote:
> >push hl
> >pop bc
> >pop af
> >push hl
> >pop de
> >push bc
> >[and so on]
> >
> >Now what the hell happens??
> >I don't get it that only one sp can hold the answer to
> >multiple register pairs being pushed/popped.
> >Maybe every regiter pair has (inside the opcode of push/pop)
> >an offset, I mean the stack is divided into a piece
> >for bc, one for hl, one for de and one for af.
>
>
>No. You are misunderstanding the basics of a stack.
>When the calc boots, it sets sp to a memory adress, where the stack should
>be located. I don't know where exactly it is in the 83, but let say it is
>$0400.
>This is in ordinary RAM, where everything else also is.
>Then when you push something, lets say hl with the value $4242,
>the only thing that happens is that hl is stored at memory pos $0400, and
>the sp will be increased to $0402.
>Now you push bc with the value $3333.
>Only thing that happens is that bc is stored at the memory pos $0402, and
>sp will be increased to $0404.
>now you push af with the value $6666.
>the only thing that happens is that af is stored at memory pos $0404, and
>the sp will be increased to $0406.
>now you _pop_ hl.
>
>code this far.
>
>push hl
>push bc
>push af
>pop  hl
>
>
>what happens now is very simple. sp will first be decreased to $0404, and
>hl is loaded with the value at this memoryposition.
>($6666 the value from the last push)
>
>then if continues in the same fasion.
>
>push something -> load at memoryposition that sp points too, increase sp
>pop something -> decrease sp, load at memoryposition sp points too.
>
>Any clearer?
>///Olle

So pushing and popping should only be done this way:

push af
  push bc
   push de
    push hl

    pop hl
   pop de
  pop bc
pop af

Right??

I thaught that someway the z80 remembered the pushes of
all the register pairs seperately.

(now I really have to take a look at some programs of mine!)

   SUCKER


_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com





Follow-Ups: