Re: A89: Stupid Stack Operation Question
[Prev][Next][Index][Thread]
Re: A89: Stupid Stack Operation Question
>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?
I use the move.w #2(A7), D0 method for accessing parameters. With this I
know that if I ever need to access them twice inside the same function it
will still be there. Another possibility is that the function uses the
stack to store stuff within the function. If the function will need to be
reading and writing these values several times then the stack pointer would
not be restored after every read, but at the end of the function.
--Nate
PS: If I still didn't answer your question, give a sample of code that has
the problem.
Follow-Ups:
References: