home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / 3b1 / 3219 < prev    next >
Encoding:
Text File  |  1992-08-27  |  1.5 KB  |  40 lines

  1. Newsgroups: comp.sys.3b1
  2. Path: sparky!uunet!digibd!steve
  3. From: steve@digibd.com (Steve Wahl)
  4. Subject: Re: Lack of libPW.a module
  5. Organization: DigiBoard Incorporated, Eden Prairie, MN
  6. Date: Thu, 27 Aug 1992 21:38:51 GMT
  7. Message-ID: <1992Aug27.213851.20578@digibd.com>
  8. Keywords: libPW PW alloca xmalloc
  9. References: <1992Aug22.004946.20370@pbhyf.PacBell.COM> <1992Aug25.235036.28469@colnet.cmhnet.org>
  10. Lines: 28
  11.  
  12. In article <1992Aug25.235036.28469@colnet.cmhnet.org> res@colnet.cmhnet.org (Rob Stampfli) writes:
  13. ...
  14. >===============================================================================
  15. ># This is optimized for the Unix PC, it won't work on some other 68k systems.
  16. ># The "and.l &-4" could be changed to "and.l &-2" if you're only running the
  17. ># code on the Unix PC.  I use this same code when cross-compiling to a 68020
  18. ># system, thus the longword alignment.
  19. >
  20. >    global    alloca
  21. >alloca:
  22. >    mov.l    (%sp)+,%a0    # pop return addr
  23. >    mov.l    (%sp),%d0    # get size argument
  24. >    and.l    &-4,%d0        # round size down to long word
  25. >    sub.l    %d0,%sp        # allocate by moving stack pointer
  26. >    mov.l    %sp,%d0        # return pointer in d0
  27. >    lea    -4(%sp),%sp    # allow caller to pop the arg
  28. >    jmp    (%a0)        # return
  29.  
  30. Rob's post mentions that you can't call this alloca() when there's
  31. something on the stack.  But beware: I believe this aproach also fails
  32. if you use register variables in your functions: think about how the
  33. compiler saves and restores the registers.
  34.  
  35. --> Steve
  36. -- 
  37. Steve Wahl               steve@digibd.com
  38. Digi International, Inc.
  39. Eden Prairie, MN         (612) 943-5387
  40.