Date : Tue, 02 Aug 1994 10:22:16 +0100 (BST)
From : amh15@... (Alan Hart)
Subject: Re: Stack behavior.
> What is confusing me is the correct stack behaviour for JSR and RTS.
> It seems to me that if a JSR were to occur, it seems to
>
> mem[0x100 + S] = PClo;
> S = S - 1;
> mem[0x100 + S] = PChi;
> S = S - 1;
I think (though I wouldn't swear) that the address is lo-hi when stored in
memory on the stack so that you can jump indirect through it. For this reason
I would expect hi to be pushed first in a descending stack like this.
> The odd thing to me is for JSR I have to -1 before I throw it on the
> stack and for a RTS I have to +1 after I pull it of the stack. Can
> anyone comment on this behaviour???? It is really bugging me!
Again, from memory, the address pushed onto the stack is PC+2, where PC is
the address of the JSR instruction itself. RTS adds one and then continue. I
would guess there is a very good reason for this. Maybe the implementation of
the 6502 was easier this way, because an instruction like BRK could use the
same logic as JSR. I don't know though. The 6502 isn't microcoded, right?
Does that mean that there is a completely separate piece of logic for each
instruction? I think it does. In which case I can't really see the point.
Someone has just suggested to me that the pipeline might explain this.
[Piece of code deleted]
> For some who have a BBC, you can try it out and find out!
> If not, I will post the answer tomorrow.
PRINT ~USR START gives 309C2830, so A is 30 hex (48 decimal).
Alan
Alan Hart - amh15@... - University of Cambridge, UK