Unix Stack Frame Questions

Stephen Clamage steve at taumet.com
Thu Apr 4 09:04:59 AEST 1991


greywolf at unisoft.UUCP (The Grey Wolf) writes:

>If there's not a stack frame, how are parameters passed to the
>function...?  And how would you return...?

>... a stack frame seems to be the most efficient way of dealing with
>calls and returns.

There is a useful distinction between using the stack and having a stack
frame.  Usually a stack frame means keeping the address of a known point in
the stack in a register, and storing known data at known places relative
to that fixed point.  Debuggers and programmers looking at the code can
determine the actual parameters and return addresses relative to the "frame
pointer".  This is convenient, but not necessarily efficient at run time.

The compiler can keep track of stack changes as it generates code, and
make all references relative to the current top of the stack.  This
eliminates the need to save and restore frame pointers and sometimes
other related data.  It makes debugging very hard, since it is not so
obvious where the parameters and local variables are.  They shift
relative to the stack top, rather than being at a fixed offset from
the frame pointer.

Finally, parameters can be passed in registers rather than being pushed
on the stack.  The return address can also be kept in a register.  A
machine with a reasonable number of registers might not need to use the
stack at all for a routine with few parameters and local variables.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.unix.internals mailing list