Argument Passing in C (Stacks)

Henry Spencer henry at utzoo.uucp
Mon Oct 10 07:46:07 AEST 1988


In article <202 at obie.UUCP> wes at obie.UUCP (Barnacle Wes) writes:
>But what about hardware without pre-decrement and post-increment
>addressing?  The Univac 1100 and many derivatives of it, for example.
>Or the IBM 360 family?  With the 360, you usually end up using a
>register for the stack pointer, and using macros [for pop and push.]
>The problem with these macros is that they are not atomic...

What you can do, to avoid this, is to allocate some anonymous temporary
variables in the stack frame and use them instead of pushing and popping
temporary values.  Actually, even the original C compiler, with the pdp11's
hardware stack support, used this approach to a small extent:  the topmost
stack location was always a temporary.  (The significance of this on the
11 was that after a function call, one less parameter had to be popped off
the stack, which was a major win since most functions have few parameters
and the 11 was particularly good at popping two or one (or zero!).)  By
doing this, you can generally avoid stack-pointer movement except as part
of the calling sequence.  It does mean that accessing small offsets from
the stack pointer or frame pointer needs to be efficient, which can
impose some constraints.  (For example, if you're not using a separate
frame pointer, on the 360 the stack must grow downward, since the 360
has positive offsets only.)
-- 
The meek can have the Earth;    |    Henry Spencer at U of Toronto Zoology
the rest of us have other plans.|uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list