Re: LF: Registers vs the stack


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

Re: LF: Registers vs the stack



On Tue, 10 Jun 1997 12:05:35 +0200 "Niklas Brunlid" <e96nbr@efd.lth.se>
writes:
>Which would be the fastest method of sending data to a library? Moving
>it to registers or pushing it to the stack?

Registers!  It takes more time to push values on the stack because
writing to memory is much slower than to registers.

>The first has the advantage that I can use MOVEM in my library, but
>the second doesn't occupy any registers in the calling program. 
>However, if I use the second, how can I use MOVEM to preserve registers?

Pushing your parameters on the stack may prevent you from having
to save/restore registers in the calling routine, but the library
routine will probably have to use registers at some point.  You can
(but shouldn't) push all registers at the start of the library
routine and pop them at the end.  When reading the stack-based
parameters, just add 60 (or however many bytes you pushed) to the
offsets.  The first parameter would normally be at 4(sp), but if
you MOVEM all registers (except A7) on the stack, it would be
at 64(sp).  This is a bad idea, because a lot of time is taken
pushing/popping the parameters.

If the routine will be called frequently, it is probably best to
let it use a few registers without preserving them.  This way, the
calling routine can preserve the registers when it needs them,
but no time will be wasted in pushing/popping those registers
when they don't need to be preserved.

--
Patrick Davidson (ariwsi@juno.com)
Visit my home page!  Stuff for Amiga, TI-85, TI-92, even DOS!
http://www.calweb.com/~kwdavids/patrick/
http://www.toptown.com/hp/ariwsi/


References: