home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / alloca.asm < prev    next >
Assembly Source File  |  1991-09-18  |  768b  |  33 lines

  1. ;80286 version of alloca(), in near code, returns far pointer
  2. ;assemble with "masm -Ml"
  3.  
  4.         .286
  5.  
  6. _TEXT   SEGMENT WORD PUBLIC 'CODE'
  7.  
  8.         ASSUME  cs:_TEXT
  9.  
  10.         PUBLIC _alloca
  11.  
  12. _alloca PROC    NEAR
  13.  
  14.         pop     cx              ; return address
  15.         pop     ax              ; amount to alloc
  16.  
  17.         add     ax,1            ; round it to 16-bit boundary
  18.         and     al,11111110B    ;
  19.  
  20.         sub     sp,ax           ; lower the stack
  21.  
  22.         mov     ax,sp           ; return ptr to base in ax
  23.         mov     dx,ss           ; segment of far pointer in dx
  24.  
  25.         sub     sp,2            ; allow for 'add sp, 2'
  26.         jmp     cx              ; jump to return address
  27.  
  28. _alloca ENDP
  29.  
  30. _TEXT   ENDS
  31.  
  32.         END
  33.