home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 364b.lha / PCQ_v1.1 / Runtime / PCQ / CheckRange.asm < prev    next >
Encoding:
Assembly Source File  |  1990-04-08  |  1.0 KB  |  38 lines

  1. *
  2. *    CheckRange.asm (of the PCQ Pascal runtime library)
  3. *    Copyright (c) 1989 Patrick Quaid
  4. *
  5. *    This routine makes sure an array index is within its
  6. *    proper bounds.  This used to be handled in-line, but
  7. *    I wanted to expand the error checking mechanism a bit.
  8. *
  9.  
  10. *    On entry, d0 is the 32-bit index.  On top of the stack is
  11. *    the maximum value, and below that is the minimum.  Note:
  12. *    To save as much code for the caller as possible, this routine
  13. *    cleans up the callers stack.   Note that this routine uses
  14. *    a0, which according to the normal call from Calls.p should
  15. *    be OK.
  16.  
  17.     XREF    _p%exit
  18.     XREF    _ExitAddr
  19.  
  20.     XDEF    _p%CheckRange
  21. _p%CheckRange
  22.     cmp.l    8(sp),d0        ; compare lower & index
  23.     blt.s    BadIndex        ; too low
  24.     cmp.l    4(sp),d0        ; compare upper & index
  25.     bgt.s    BadIndex        ; too high
  26. FixStack
  27.     move.l    (sp),a0            ; get return address
  28.     adda.l    #12,sp            ; get return, plus 2 ops
  29.     move.l    a0,-(sp)        ; push back return
  30.     rts
  31. BadIndex
  32.     move.l    (sp),_ExitAddr        ; address of CALLER
  33.     move.l    #60,d0            ; set up for call
  34.     jsr    _p%exit            ; blow up
  35.     bra    FixStack        ; we might return...
  36.  
  37.     END
  38.