Re: A92: Stack and return values


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

Re: A92: Stack and return values




Kyle Stemen wrote:
> 
> Niklas Brunlid wrote:
> 
> > Aaron Hill wrote:
> > >
> > > Hello all,
> > >
> > > I want to use the stack to return a value.  Because JSR stores the PC on the
> > > SP before jumping and RTS needs this value intact, I can't just push the
> > > return value on the stack.  Does anyone know how I can do a return value
> > > without using the data registers?
> >
> > Easy - just pop the RTS value to a temporary register or variable, push
> > your return values, and the push the RTS value again.
> 
>   What would happen if you put it on the stack after the RTS value, but didn't
> push it there. Just put it there. The RTS value would be popped from the stack,
> and an instruction could be saved. By the way how big is the RTS value?

Unless the stack'r *really* full (very unlikely) you could do it that
way, though it's a "dirty" solution. In Fargo, you're the only one who
uses the stack - unless you've got some interrupts running, and that
includes the TI:s own (keyreading and stuff). With the method I
suggested you don't have to worry about anything, since you've reserved
the necesary stack space already.


References: