[comp.sys.nsc.32k] alloca.s for ICM3216

sverre@fesk.seri.gov (Sverre Froyen) (11/27/89)

Here is a version of alloca.s for National's ICM3216.  It
works with (at least) GNU emacs, bison, and make.  The version
supplied in libPW.a is broken.

----- cut here ---------- cut here ---------- cut here -----
#
# allocate space on stack (stack grows downward)
# $Id: alloca.s,v 1.2 89/10/25 09:22:45 bin Exp $
#
# GP registers are saved just below the stack pointer
#
# stack:
# on exit:	register 5 (4 bytes) (up to five registers)
#		register 4 (4 bytes)
#		register 3 (4 bytes)
#		register 2 (4 bytes)
#		register 1 (4 bytes)
#		n'th byte allocated
#		n-1'th byte allocated
#		...
#		second byte allocated
#	r0->	first byte allocated (adusted to 4 byte boundary)
# 		register 5 (4 bytes) (five registers assumed)
#		register 4 (4 bytes)
#		register 3 (4 bytes)
#		register 2 (4 bytes)
#		register 1 (4 bytes)
#	sp->	extra 4 bytes (was: argument to alloca) (popped by caller)
#
# on entry:	register 5 (4 bytes) (up to five registers)
#		register 4 (4 bytes)
#		register 3 (4 bytes)
#		register 2 (4 bytes)
#		register 1 (4 bytes)
#		argument to alloca (4 bytes)
#	sp->	return address (4 bytes)
# 
	.file	"alloca.s"
	.text
	.globl	_alloca
_alloca:
	movd	tos,r2		# pop return address
	movd	$0,r0		# error return value
	cmpqd	$0,0(sp)	# check for positive argument
	bge	.LL1		# skip if zero or negative
	negd	tos,r0		# pop (negative of) argument
	sprd	sp,r1		# save old stack pointer
	addd	r1,r0		# grow stack by amount to allocate
	bicd	$3,r0		# grow stack to 4-byte boundary
	lprd	sp,r0		# load new stack pointer
	adjspb	$24		# make space for registers and argument
	movmd	0(r1),4(sp),$4	# copy 4 GP registers (max 16 bytes)
	movd	16(r1),20(sp)	# copy 5th GP register
.LL1:	jump	0(r2)		# return
----- cut here ---------- cut here ---------- cut here -----
-- 
Sverre Froyen
INTERNET: sverre@fesk.seri.gov
UUCP:     boulder!fesk!sverre, sunpeaks!seri!fesk!sverre
BITNET:   froyen@csugold.bitnet