home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
lang
/
bison.sit
/
alloca.a
next >
Wrap
Text File
|
1989-01-02
|
1KB
|
48 lines
;;
;; Alloca() for Macintosh Programmer's Workshop C 2.0.2.
;; 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
;;
CASE ON
macro
BlockMove
dc.w $A02E
endm
SAVESIZE EQU 48 ; 12 registers times 4 bytes each
_alloca PROC EXPORT
link a6,#0
export alloca
alloca
move.l (sp)+,a1 ; pop return address
move.l (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 #-4,sp ; new top of stack
jmp (a0) ; return to caller
unlk a6
rts
STRING ASIS
dc.b 'ALLOCA '
ENDP
END