Re: A89: Stupid Stack Operation Question


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

Re: A89: Stupid Stack Operation Question




On Thu, 14 Jan 1999, Nate Mueller wrote:

> 
> >Why is that data added back to the stack?
> >
> >I know it is to correct the stack back to it's original
> >position and I know how the stack operates but, doesn't 
> >the called routine do that when it obtains (pops) these 
> >passed parameters?  
> >
> >Why is correcting the stack necessary.
> 
> The system stack in asm is different then one in a HLL language.  In asm
> you have acess to all values in the stack at all times.  Most programers
> just read the values off the stack during a function, they do not play with
> the stack pointer.  Temporary data is often stored in the stack as well.
> In fact, it is a better programing method to de-allocate all of the stack
> data needed for the function at once -- it makes programs much easier to
> de-bug.

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.
         ; 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.

Now it altogether possible to access the data with something that does not
change the value of the SP.  Like move.w #2(A7), D0.  And further I'm not
sure that one should ever mix and match these two methods.

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?

> 
> 	--Nate
> 

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

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


Follow-Ups: References: