Argument Passing in C (Stacks)

Barnacle Wes wes at obie.UUCP
Thu Oct 6 15:03:57 AEST 1988


In message <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.

In article <699 at wsccs.UUCP>, dharvey at wsccs.UUCP (David Harvey) replies:
> It seems to me that any register based hardware with register indirect
> mode and, post-increment and pre-decrement instructions will do the
> trick for you.  [...]

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 like (forgive me if
the syntax is wrong, it has been quite a few years since I wrote a
BAL program :-)

POP	MACRO	a
	MOV	(R5),a
	ADD	#4,R5
	ENDM

PUSH	MACRO	a
	SUB	#4,R5
	MOV	a,(R5)
	ENDM

The problem with these macros is that they are not atomic.  I can't
think of any straightforward reasons why this is a problem, but I'm sure
it would cause problems somewhere, somehow.

-- 
                     {hpda, uwmcsd1}!sp7040!obie!wes

         "How do you make the boat go when there's no wind?"
                                 -- Me --



More information about the Comp.lang.c mailing list