Re: A89: Stupid Stack Operation Question


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

Re: A89: Stupid Stack Operation Question




Yep! you are absolutely right.

On Thu, 14 Jan 1999, Jimmy [iso-8859-1] Mårdell wrote:

> 
> At 08:58 1999-01-14 -0800, you wrote:
> >But, you did not answer my question.  Sure you have access to all stack
> >data at all times.  But usually one gets data as LIFO using some sort of
> >pop (which restores SP), like move.w  (A7)+, D0.  
> >
> >If I do: move.w  D0, -(A7)   ; pushes D0 onto stack
> >         jsr     myRoutine
> >         ; some restoration here is only necessary if SP is same as
> >         ; before jsr.
> >
> >Doesn't the myRoutine usually access the data with:
> >         move.w  (A7)+, D0   ; pops the Data and restores SP pointer.
> 
> Nope, this would pop the return address... or part of it anyway. Remember
> that a call (jsr or bsr) pushes the program counter on the stack.
> 
> >         ; do something
> >         rts                 ; returns to calling program with original SP
> >                             ; restored.
> >
> >So, if it does work this way, the stack is already restored when the
> >return occurs.  If fact if the SP is restored to it's original data and
> >I add something to that value, I have grown the stack unnecessarily.
> 
> But it doesn't work that way :) It's much easier to access the pushed
> data with a move #x(a7),d0 instruction. Also, if popping was done, you
> would only be able to access the value once.
> 
> >Does TI use this latter method of accessing subroutine parameters?  Is
> >that maybe why the SP is corrected.  That is, access the parameters
> >without modifying the SP?
> 
> Right :)
> 
> //Jimmy Mårdell
> 
> E-mail: yarin@acc.umu.se
> Homepage: http://www.acc.umu.se/~yarin/
> 
> 

----------------------------------------------------
Shoot-to-Win

Protect the 2nd Amendment
----------------------------------------------------


References: