[comp.sys.hp] Alloca for HP-UX 5.22

denny@dsndata.UUCP (Denny Page) (05/19/87)

Improvement suggestions are welcomed.

-denny

---

#
#	allocate temporary memory from the stack
#
#	char *alloca(size)
#	unsigned size;
#
#	denny	05/17/86
#

		set	SREG,10			# possible regs (d2-d7 a2-a5)
		set     PROBE,-128		# safety for C compiler

		text

		global	_alloca

_alloca:	equ	.			# start here

		mov.l	(%sp)+,%d0		# return address
		mov.l	(%sp)+,%d1		# block size

		neg.l	%d1			# twist & shout
		and.w	&-4,%d1			# longword align

		lea	(%sp),%a0		# bottom of old regs
		lea	-SREG*4(%sp,%d1.l),%a1	# bottom of new regs
		lea	-4(%a1),%sp		# new stack pointer
		tst.b	PROBE(%sp)		# create pages

		movq	&SREG-1,%d1		# load loop count
sregs_loop:	mov.l	(%a0)+,(%a1)+		# copy register
		dbra	%d1,sregs_loop		# loop until done

		exg	%d0,%a1			# swap return & block
		jmp	(%a1)			# rts
-- 

Denny	dsndata!denny		[Martha, the Clones are loose again!]