Argument Passing in C

Clayton Cramer cramer at optilink.UUCP
Wed Sep 28 09:41:16 AEST 1988


In article <69210 at sun.uucp>, swilson%thetone at Sun.COM (Scott Wilson) writes:
> Can someone explain to me what the difference is between a hardware stack
> and a software stack?  I worked on a C compiler project once where
> one person said the target machine "doesn't even have a hardware stack."
> I asked what the difference was between the target machine and, say, a 68000.
> The answer was the 68000 had a stack because it supported addressing modes
> like "movl d7, at sp-" whereas the target machine required you to use two
> instructions, first a move then an explicit decrement of the stack pointer.
> So what?, I thought.  So which machines have a hardware stack and which
> don't and how do the differences appear to, say, an assembly language
> programmer.
> 
> --
> Scott Wilson		arpa: swilson at sun.com

This may be going further back into prehistory than you intended, but I
worked on a machine called the Univac 1219 that had no concept of a
"stack pointer".  Subroutine calls were implemented with an instruction
called "B7IJ", which took the current return address and stuffed it into
the word at the beginning of the subroutine you were calling.  When your
subroutine was complete, you executed a return by doing an indirect
jump through the address in the first word of the subroutine.  Needless
to say, there was no way to do recursion without tremendous effort.

An example of a machine with a nearly useless hardware stack is the 6502.
The stack pointer is an 8-bit register, and the first eight bits of the
hardware stack pointer address are optionally definable by a jumper.
As a consequence, the hardware stack is only 256 bytes long.  If you
want to do anything more complicated than a simple video game, or perhaps
a simple process control system, plan on building your own stack 
manipulation subroutines.

And you thought the 8086 family was primitive!
-- 
Clayton E. Cramer
..!ames!pyramid!kontron!optilin!cramer



More information about the Comp.lang.c mailing list