Argument Passing in C

Barry Margolin barmar at think.COM
Thu Sep 22 05:15:44 AEST 1988


In article <69210 at sun.uucp> swilson at sun.UUCP (Scott Wilson) writes:
>Can someone explain to me what the difference is between a hardware stack
>and a software stack?

A hardware stack is one that has explicit machine instructions and/or
addressing modes for manipulating and using a register (or registers)
as a stack pointer.  Frequently there is a dedicated register for this
purpose, and it is used implicitly by some of these instructions.

The example you gave was good.  If you can push or pop a value on a
stack in one instruction, rather than having to increment the stack
pointer in a separate instruction, you have the rudiments of a
hardware stack (of course, autoincrementing is also useful for
stepping through an array).

Other operations sometimes supplied with a hardware stack are special
call and return instructions that automatically manipulate the stack.
For example, if the return instruction knows that the saved PC is at a
particular offset from the stack pointer register and automatically
pops it into the PC and unwinds the stack, that is a hardware stack.

The Honeywell hardware that Multics runs on doesn't have a hardware
stack, but there are conventions that a particular register was
always used as the stack pointer.  The assembler has a RETURN
pseudo-op that is actually a built-in macro that does all the stack
manipulation for returning (actually, it transfers to a standard
shared routine that does the work).

Barry Margolin
Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.lang.c mailing list