home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel Volume 2 #1
/
carousel.iso
/
mactosh
/
lang
/
bison.sit
/
alloca.s
< prev
next >
Wrap
Text File
|
1989-01-02
|
1KB
|
41 lines
;;
;; Alloca() for Aztec C v 3.6c.
;; alloca(n) allocates n bytes of storage in the stack
;; frame of the caller.
;;
;; Allows caller to save up to 12 registers on the stack
;; at caller's procedure entry, and pop them off on exit.
;;
;; Calling routine must be set up to align stack pointer between
;; calls to functions, or this will fail.
;;
;; Earle R. Horton Sunday, January 1, 1989
;;
macro BlockMove
dc.w $A02E
endm
SAVESIZE EQU 48 ; 12 registers times 4 bytes each
link a6,#0 ; So this procedure can have a label.
public _alloca
_alloca:
move.l (sp)+,a1 ; pop return address
clr.l d0 ; clear register
move.w (sp)+,d0 ; pop parameter = size in bytes
move.l sp,a0 ; save stack pointer, source parameter for BlockMove
addq.l #3,d0 ; round size up to long word
andi.l #-4,d0 ; mask out lower two bits of size
addi.l #SAVESIZE,d0 ; allow for up to 12 registers saved by caller
sub.l d0,sp ; allocate by moving stack pointer
move.l a1,-(sp) ; push return address
lea 4(sp),a1 ; new save reg area, destination pointer for BlockMove
move.l #SAVESIZE,d0 ; bytes to move
BlockMove ; move save area
move.l (sp)+,a0 ; pop return address
move.l sp,d0 ; stack pointer to d0
addi.l #SAVESIZE,d0 ; return pointer to just above new save area
adda.w #-2,sp ; new stack pointer
jmp (a0) ; return to caller
unlk a6
rts
dc.b 'ALLOCA ' ; Macsbug Label