home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk399.lzh / CCLib / Con / setjmp.asm < prev    next >
Assembly Source File  |  1990-11-02  |  887b  |  43 lines

  1. ;
  2. ; setjmp - saves the context of a process(?) in a buffer so a call
  3. ;       to longjmp can restore it.
  4. ;
  5. ;
  6. ;
  7.     XDEF _setjmp
  8.     XDEF _longjmp
  9.  
  10. ; CODE setjmp_code  (this had to be removed as Aztec doesn't like)
  11.     EVEN
  12. _setjmp:
  13.     move.l    4(sp),a0        ; get pointer to save array
  14.     move.l    (sp),a1        ; get return address
  15.     move.l    a1,(a0) ; save return address
  16.     movem.l d2-d7/a2-a7,4(a0)
  17.  
  18.     clr.l    d0
  19.     rts
  20.  
  21. ;
  22. ; longjmp - restores the context saved by a call to setjmp, which causes
  23. ;        the process to do a jump to where the setjmp was called
  24. ;        i.e. looks like the setjmp returned again.
  25. ;
  26. ;
  27. _longjmp:
  28.     move.l    4(sp),a0        ;get pointer to save_env
  29.     move.l    8(sp),d0        ;get return value
  30.     tst.l    d0
  31.     bne    not_zero    ; if the return value is zero set it to 1
  32.     move.l    #1,d0
  33. not_zero:
  34.     movem.l 4(a0),d2-d7/a2-a7
  35.     move.l    (a0),(sp)       ; write return address
  36.  
  37.     rts ;here goes nothing.
  38.  
  39.     END
  40.  
  41.  
  42.  
  43.