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

  1. Newsgroups: comp.sys.3b1
  2. Path: sparky!uunet!usc!sol.ctr.columbia.edu!destroyer!wsu-cs!uts.cc.wayne.edu!rwilson
  3. From: rwilson@uts.cc.wayne.edu (Ron Wilson)
  4. Subject: Re: Lack of libPW.a module
  5. Message-ID: <1992Aug28.184411.25578@uts.cc.wayne.edu>
  6. Keywords: libPW PW alloca xmalloc
  7. Organization: Wayne State University, Detroit Mich.
  8. References: <1992Aug22.004946.20370@pbhyf.PacBell.COM> <1992Aug25.235036.28469@colnet.cmhnet.org> <1992Aug27.213851.20578@digibd.com>
  9. Date: Fri, 28 Aug 1992 18:44:11 GMT
  10. Lines: 36
  11.  
  12. In article <1992Aug27.213851.20578@digibd.com> steve@digibd.com (Steve Wahl) writes:
  13. >In article <1992Aug25.235036.28469@colnet.cmhnet.org> res@colnet.cmhnet.org (Rob Stampfli) writes:
  14. >...
  15. >>===============================================================================
  16. >># This is optimized for the Unix PC, it won't work on some other 68k systems.
  17. >># The "and.l &-4" could be changed to "and.l &-2" if you're only running the
  18. >># code on the Unix PC.  I use this same code when cross-compiling to a 68020
  19. >># system, thus the longword alignment.
  20. >>
  21. >>    global    alloca
  22. >>alloca:
  23. >>    mov.l    (%sp)+,%a0    # pop return addr
  24. >>    mov.l    (%sp),%d0    # get size argument
  25. >>    and.l    &-4,%d0        # round size down to long word
  26. >>    sub.l    %d0,%sp        # allocate by moving stack pointer
  27. >>    mov.l    %sp,%d0        # return pointer in d0
  28. >>    lea    -4(%sp),%sp    # allow caller to pop the arg
  29. >>    jmp    (%a0)        # return
  30. >
  31. >Rob's post mentions that you can't call this alloca() when there's
  32. >something on the stack.  But beware: I believe this aproach also fails
  33. >if you use register variables in your functions: think about how the
  34. >compiler saves and restores the registers.
  35. >
  36. >--> Steve
  37.  
  38. The problem is NOT that something is on the stack, but rather using this
  39. alloca inside an expression that uses the stack will corrupt the stack.
  40. As for register variables, they shouldn't be affected: Once "you" start
  41. executing code in the BODY ofa function or a block of code - as opposed
  42. to executable code imbedded in the definition section - all of the
  43. variables - including register variables - will be allocated.
  44.  
  45. As long as you only use alloca() in simple asignment statements - = only,
  46. not even if ((x = alloca(n)) == NULL) - functions using alloca() should
  47. work just fine.
  48.