home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lisp / interpre / xlispplu / sources / longjmp.asm < prev    next >
Assembly Source File  |  1992-02-03  |  1KB  |  56 lines

  1. ; setjmp/longjmp for Microway C 386
  2. ; Written by Tom Almy, placed in public domain.
  3. ; This is missing from the Microway distribution!
  4.  
  5. ; The following needs to be put in a file "setjump.h"
  6.  
  7. ; typedef int jmp_buf[11]; /* ip cs bp sp ds es fs gs si di bx */
  8. ; extern int setjmp(/*jmp_buf env*/);
  9. ; extern void longjmp(/*jmp_buf env, int val*/);
  10.  
  11.     .386p
  12. dataseg segment 'data'
  13. dataseg ends
  14. codeseg segment er dword public use32 'code'
  15.     assume cs:codeseg, ds:dataseg
  16.     public _setjmp,_longjmp
  17.     align 4
  18. _setjmp proc near
  19.     mov eax, 4[esp] ; jmp_buf
  20.     mov edx, 0[esp] ; return address
  21.     mov 0[eax],edx  ;  ip
  22.     mov 8[eax],ebp  ;  other registers
  23.     lea edx, 4[esp] ;  stack pointer (after return)
  24.     mov 12[eax],edx
  25.     mov 20[eax],es
  26.     mov 24[eax],fs
  27.     mov 28[eax],gs
  28.     mov 32[eax],esi
  29.     mov 36[eax],edi
  30.     mov 40[eax],ebx
  31.     xor eax, eax    ; return zero
  32.     ret
  33. _setjmp endp
  34.     align 4
  35. _longjmp proc near
  36.     mov eax, 4[esp]     ; arg
  37.     mov ecx, 8[esp] ; return value
  38.     mov esp, 12[eax]    ; reset stack
  39.     push    0[eax]      ; return ip value
  40.     mov ebp, 8[eax]
  41.     mov es, 20[eax]
  42.     mov fs, 24[eax]
  43.     mov gs, 28[eax]
  44.     mov esi, 32[eax]
  45.     mov edi, 36[eax]
  46.     mov ebx, 40[eax]
  47.     mov eax, ecx    ; return value
  48.     or  eax, eax    ; mustnt be zero
  49.     jnz SHORT nonzero
  50.     inc eax
  51. nonzero:
  52.     ret
  53. _longjmp endp
  54. codeseg ends
  55.     end
  56.