home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / readline / x386-alloca.s < prev    next >
Text File  |  1991-08-30  |  2KB  |  64 lines

  1. ;; alloca386.s 1.2
  2. ;; GNU-compatible stack allocation function for Xenix/386.
  3. ;; Written by Chip Salzenberg at ComDev.
  4. ;; Last modified 90/01/11
  5. ;;> Is your alloca clearly better than the one in i386-alloca.s?  I haven't
  6. ;;> looked at either.
  7. ;;
  8. ;;They're different because Xenix/386 has a different assembler.  SCO
  9. ;;Xenix has the Microsoft C compiler and the Microsoft macro assembler,
  10. ;;called "masm".  MASM's assembler syntax is quite different from AT&T's
  11. ;;in all sorts of ways.  Xenix people can't use the AT&T version.
  12. ;;-- 
  13. ;;Chip Salzenberg at ComDev/TCT     <chip@tct.uucp>, <uunet!ateng!tct!chip>
  14.  
  15.     TITLE   $alloca386
  16.  
  17.     .386
  18. DGROUP    GROUP    CONST, _BSS, _DATA
  19. _DATA    SEGMENT  DWORD USE32 PUBLIC 'DATA'
  20. _DATA      ENDS
  21. _BSS    SEGMENT  DWORD USE32 PUBLIC 'BSS'
  22. _BSS      ENDS
  23. CONST    SEGMENT  DWORD USE32 PUBLIC 'CONST'
  24. CONST      ENDS
  25. _TEXT    SEGMENT  DWORD USE32 PUBLIC 'CODE'
  26.     ASSUME   CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  27.  
  28.     PUBLIC  _alloca
  29. _alloca PROC NEAR
  30.  
  31. ; Get argument.
  32.     pop     edx             ; edx -> return address
  33.     pop     eax             ; eax = amount to allocate
  34.  
  35. ; Validate allocation amount.
  36.     add     eax,3
  37.     and     eax,not 3
  38.     cmp     eax,0
  39.     jg      aa_size_ok
  40.     mov     eax,4
  41. aa_size_ok:
  42.  
  43. ; Allocate stack space.
  44.     mov     ecx,esp         ; ecx -> old stack pointer
  45.     sub     esp,eax         ; perform allocation
  46.     mov     eax,esp         ; eax -> new stack pointer
  47.  
  48. ; Copy the three saved register variables from old stack top to new stack top.
  49. ; They may not be there.  So we waste twelve bytes.  Big fat hairy deal.
  50.     push    DWORD PTR 8[ecx]
  51.     push    DWORD PTR 4[ecx]
  52.     push    DWORD PTR 0[ecx]
  53.  
  54. ; Push something so the caller can pop it off.
  55.     push    eax
  56.  
  57. ; Return to caller.
  58.     jmp     edx
  59.  
  60. _alloca ENDP
  61.  
  62. _TEXT   ENDS
  63.     END
  64.