home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog_c / suplib.lzh / SUPLIB / SRC / STACKCHECK.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-08-16  |  2.1 KB  |  63 lines

  1.  
  2.         ;    STACKCHECK.ASM
  3.         ;
  4.         ;    SetStackCheck(#bytes)             fill stack downward #bytes
  5.         ;    long #bytes
  6.         ;
  7.         ;    #bytes = GetStackCheck(#bytes)    return stack used
  8.         ;    long #bytes
  9.         ;
  10.         ;    These routines are used to determine how much stack a
  11.         ;    subroutine takes up.  SetStackCheck() lays down a pattern
  12.         ;    on the stack below the sp (of #bytes).  Thus, do not
  13.         ;    specify a value larger than the actual stack that is
  14.         ;    available from point of call.
  15.         ;
  16.         ;    GetStackCheck() scans from the lowest bound upward until
  17.         ;    the pattern fails, and the number of bytes from the top
  18.         ;    to the fail point is returned.    The idea is to call
  19.         ;    SetStackCheck(), call some other subroutine(s), then
  20.         ;    call GetStackCheck() to see how much stack they had used.
  21.         ;
  22.         ;    Warning: values will differ as EXEC pushes stuff on the user
  23.         ;    stack during a context switch.    Always give yourself about
  24.         ;    100 bytes more stack than you seem to need, unless you are
  25.         ;    using the 68881 or other coprocessor in which case you need
  26.         ;    to give yourself more.
  27.         ;
  28.         ;    warning: do not specify values larger than 32767 (just to
  29.         ;    be safe, theoretically you can specify up to 128K).  due to
  30.         ;    the nature of these routines I doubt you would specify more
  31.         ;    than that anyway.  Remember not to specify more bytes than
  32.         ;    stack you actually have.
  33.  
  34.         section CODE
  35.  
  36.         XDEF    _SetStackCheck
  37.         XDEF    _GetStackCheck
  38.  
  39. _SetStackCheck:
  40.         move.l  4(sp),D0        ; # of bytes (max 32K)
  41.         lsr.l   #1,D0        ; # of words
  42.         move.l  sp,A0
  43. .ss1        move.w  #$1234,-(A0)
  44.         dbf     D0,.ss1
  45.         rts
  46.  
  47. _GetStackCheck:
  48.         move.l  4(sp),D0
  49.         bclr    #0,D0        ; world align
  50.         move.l  sp,A0
  51.         sub.l   D0,A0        ; start at bottom and move upwards
  52.         lsr.l   #1,D0        ; # of words
  53.         subq.l  #1,D0        ; 1 less (else would overwrite retaddr)
  54. .gs1        cmp.w   #$1234,(A0)+    ; until done or not equal
  55.         dbne    D0,.gs1
  56.         move.l  sp,D0
  57.         sub.l   A0,D0
  58.         add.l   #8,D0        ; 8 more used than that to include
  59.         rts             ;  stack used by Get/SetStackCheck
  60.  
  61.         END
  62.  
  63.