home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / ADVMSDOS.ZIP / ZERODIV.ASM < prev   
Encoding:
Assembly Source File  |  1986-06-19  |  2.5 KB  |  123 lines

  1.          name      zdivide
  2.          page      55,132
  3.          title     'ZERODIV.ASM --- Divide by Zero Handler'
  4. ;
  5. ; ZERODIV.ASM --- Divide-by-Zero Interrupt Handler
  6. ;
  7. ; Demonstrates a "well-behaved" interrupt handler
  8. ; that becomes resident after MS-DOS is running.
  9. ;
  10. ; Copyright (C) 1985 Ray Duncan
  11. ;
  12. ; To assemble, link, and convert this program into a COM file:
  13. ;    
  14. ;    C>MASM ZERODIV;
  15. ;    C>LINK ZERODIV;
  16. ;    C>EXE2BIN ZERODIV.EXE ZERODIV.COM
  17. ;       C>DEL ZERODIV.EXE
  18. ;
  19.  
  20. cr    equ     0dh           ;ASCII carriage return
  21. lf      equ     0ah           ;ASCII line feed
  22. beep    equ    07h        ;ASCII bell code
  23. backsp    equ    08h        ;ASCII backspace code
  24.  
  25. cseg     segment    para public 'CODE'
  26.  
  27.     org    100H      
  28.  
  29.     assume     cs:cseg,ds:cseg,es:cseg,ss:cseg
  30.  
  31. Init    proc     near      
  32.                 ;reset interrupt 0 vector to 
  33.     mov    dx,offset Zdiv    ;address of new handler
  34.     mov    ax,2500h    ;function 25H, interrupt 0
  35.     int    21h        ;transfer to MS-DOS
  36.  
  37.                 ;print identification message
  38.     mov    dx,offset signon
  39.     mov    ah,9
  40.     int    21h
  41.  
  42.                 ;DX = paragraphs of memory
  43.                 ;to reserve 
  44.     mov    dx,((offset Pgm_Len+15)/16)+10h
  45.  
  46.     mov    ax,3100h    ;exit and stay resident, with
  47.     int    21h        ;return code = 0
  48.  
  49. Init    endp
  50.  
  51. Zdiv    proc    far        ;this is the zero-divide
  52.                 ;hardware interrupt handler
  53.  
  54.     sti            ;enable interrupts
  55.     push    ax        ;save general registers
  56.     push    bx
  57.     push    cx
  58.     push    dx
  59.     push    si
  60.     push    di
  61.     push    bp
  62.     push    ds
  63.     push    es
  64.  
  65.     mov    ax,cs          ;print warning "Divide by Zero"
  66.     mov    ds,ax        ; and "Continue or Quit? "
  67.     mov    dx,offset warn
  68.     mov    ah,9
  69.     int    21h
  70.  
  71. Zdiv1:    mov    ah,1        ;read keyboard
  72.     int    21h
  73.  
  74.     cmp    al,'C'        ;is it C or Q?
  75.     je    Zdiv3        ;jump, it's a C
  76.     cmp    al,'Q'
  77.     je    Zdiv2        ;jump, it's a Q
  78.  
  79.     mov    dx,offset bad    ;illegal entry, send
  80.     mov    ah,9        ;a beep, erase the bad char.
  81.     int    21h        ;and try again
  82.  
  83.     jmp    Zdiv1
  84.  
  85. Zdiv2:    mov    ax,4cffh    ;user wishes to abort
  86.     int    21h        ;program, exit with
  87.                 ;return code = 255
  88.  
  89. Zdiv3:    mov    dx,offset crlf  ;user wishes to continue,
  90.     mov    ah,9        ;send carriage ret-line feed    
  91.     int    21h
  92.  
  93.     pop    es        ;restore general registers
  94.     pop    ds        ;and resume execution
  95.     pop    bp
  96.     pop    di
  97.     pop    si
  98.     pop    dx
  99.     pop    cx
  100.     pop    bx
  101.     pop    ax
  102.     iret
  103.  
  104. Zdiv    endp
  105.  
  106. signon    db       cr,lf,'Divide by Zero Interrupt '
  107.     db    'Handler installed.'
  108.     db    cr,lf,'$'
  109.  
  110. warn    db    cr,lf,lf,'Divide by Zero detected: '
  111.     db    cr,lf,'Continue or Quit (C/Q) ? '
  112.     db    '$'
  113.  
  114. bad    db    beep,backsp,' ',backsp,'$'
  115.  
  116. crlf    db    cr,lf,'$'
  117.  
  118. Pgm_Len    equ    $-Init
  119.  
  120. cseg     ends
  121.  
  122.     end    init
  123.