home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1989 / 22 / setjmp.asm < prev    next >
Assembly Source File  |  1989-11-10  |  2KB  |  61 lines

  1.  
  2.  
  3.  
  4.  
  5. CODE    SEGMENT BYTE PUBLIC
  6.         ASSUME CS:CODE
  7.         PUBLIC SetJmp, LongJmp
  8.  
  9. SetJmp  PROC FAR
  10.         PUSH    BP
  11.         MOV     BP, SP
  12.         LES     DI, 6[BP]       ; Get address of JumpBuffer
  13.         CLD
  14.         LEA     AX, 6[BP]       ; Save SP
  15.         ADD     AX, 4
  16.         STOSW
  17.         MOV     AX, SS
  18.         STOSW                   ; Save SS
  19.         MOV     AX, 4[BP]
  20.         STOSW                   ; Save CS
  21.         MOV     AX, 2[BP]
  22.         STOSW                   ; Save IP
  23.         MOV     AX, [BP]
  24.         STOSW                   ; Save BP
  25.         MOV     AX, DS
  26.         STOSW                   ; Save DS
  27.         XOR     AX, AX          ; Return a value of 0 from SetJmp
  28.         POP     BP              ; Restore previous frame pointer
  29.         RET     4               ; Clean up stack and return
  30. SetJmp  ENDP
  31.  
  32. LongJmp PROC    FAR
  33.         PUSH    BP
  34.         MOV     BP, SP
  35.         MOV     BX, 6[BP]       ; Get the return code
  36.         CMP     BX, 1   ; If it is zero then return a value of 1
  37.         ADC     BX, 0   ;       so that LongJmp never returns 0
  38.         LDS     SI, 8[BP]       ; DS:SI points to JumpBuffer
  39.         CLD
  40.         LODSW           ;Restore SS
  41.         MOV     SS, [SI]
  42.         MOV     SP, AX  ;Restore SP
  43.         LODSW
  44.         LODSW
  45.         PUSH    AX      ;Push CS and IP onto the stack
  46.         LODSW
  47.         PUSH    AX
  48.         LODSW
  49.         MOV     BP, AX  ;Restore BP
  50.         LODSW
  51.         MOV     DS, AX  ;Restore DS
  52.         MOV     AX, BX  ;RetValue in AX
  53.         RET             ;Return with CS:IP from JumpBuffer
  54. LongJmp ENDP
  55. CODE    ENDS
  56.         END
  57.  
  58.  
  59.  
  60.  
  61.