home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / lang / bison.sit / alloca.s < prev    next >
Text File  |  1989-01-02  |  1KB  |  41 lines

  1. ;;
  2. ;; Alloca() for Aztec C v 3.6c.
  3. ;; alloca(n) allocates n bytes of storage in the stack
  4. ;; frame of the caller.
  5. ;;
  6. ;; Allows caller to save up to 12 registers on the stack
  7. ;; at caller's procedure entry, and pop them off on exit.
  8. ;;
  9. ;; Calling routine must be set up to align stack pointer between
  10. ;; calls to functions, or this will fail.
  11. ;;
  12. ;; Earle R. Horton Sunday, January 1, 1989
  13. ;;
  14.     macro    BlockMove 
  15.     dc.w    $A02E
  16. endm
  17. SAVESIZE    EQU    48    ; 12 registers times 4 bytes each
  18.     link    a6,#0        ; So this procedure can have a label.
  19.     public _alloca
  20. _alloca:
  21.     move.l    (sp)+,a1    ; pop return address
  22.     clr.l    d0        ; clear register
  23.     move.w    (sp)+,d0    ; pop parameter = size in bytes
  24.     move.l    sp,a0        ; save stack pointer, source parameter for BlockMove
  25.     addq.l    #3,d0        ; round size up to long word
  26.     andi.l    #-4,d0        ; mask out lower two bits of size
  27.     addi.l    #SAVESIZE,d0    ; allow for up to 12 registers saved by caller
  28.     sub.l    d0,sp        ; allocate by moving stack pointer
  29.     move.l    a1,-(sp)    ; push return address
  30.     lea    4(sp),a1    ; new save reg area, destination pointer for BlockMove
  31.     move.l    #SAVESIZE,d0    ; bytes to move
  32.     BlockMove        ; move save area
  33.     move.l    (sp)+,a0    ; pop return address
  34.     move.l    sp,d0        ; stack pointer to d0
  35.     addi.l    #SAVESIZE,d0    ; return pointer to just above new save area
  36.     adda.w    #-2,sp        ; new stack pointer
  37.     jmp    (a0)        ; return to caller
  38.     unlk    a6
  39.     rts
  40.     dc.b    'ALLOCA  '    ; Macsbug Label
  41.