home *** CD-ROM | disk | FTP | other *** search
- name zdivide
- page 55,132
- title 'ZERODIV.ASM --- Divide by Zero Handler'
- ;
- ; ZERODIV.ASM --- Divide-by-Zero Interrupt Handler
- ;
- ; Demonstrates a "well-behaved" interrupt handler
- ; that becomes resident after MS-DOS is running.
- ;
- ; Copyright (C) 1985 Ray Duncan
- ;
- ; To assemble, link, and convert this program into a COM file:
- ;
- ; C>MASM ZERODIV;
- ; C>LINK ZERODIV;
- ; C>EXE2BIN ZERODIV.EXE ZERODIV.COM
- ; C>DEL ZERODIV.EXE
- ;
-
- cr equ 0dh ;ASCII carriage return
- lf equ 0ah ;ASCII line feed
- beep equ 07h ;ASCII bell code
- backsp equ 08h ;ASCII backspace code
-
- cseg segment para public 'CODE'
-
- org 100H
-
- assume cs:cseg,ds:cseg,es:cseg,ss:cseg
-
- Init proc near
- ;reset interrupt 0 vector to
- mov dx,offset Zdiv ;address of new handler
- mov ax,2500h ;function 25H, interrupt 0
- int 21h ;transfer to MS-DOS
-
- ;print identification message
- mov dx,offset signon
- mov ah,9
- int 21h
-
- ;DX = paragraphs of memory
- ;to reserve
- mov dx,((offset Pgm_Len+15)/16)+10h
-
- mov ax,3100h ;exit and stay resident, with
- int 21h ;return code = 0
-
- Init endp
-
- Zdiv proc far ;this is the zero-divide
- ;hardware interrupt handler
-
- sti ;enable interrupts
- push ax ;save general registers
- push bx
- push cx
- push dx
- push si
- push di
- push bp
- push ds
- push es
-
- mov ax,cs ;print warning "Divide by Zero"
- mov ds,ax ; and "Continue or Quit? "
- mov dx,offset warn
- mov ah,9
- int 21h
-
- Zdiv1: mov ah,1 ;read keyboard
- int 21h
-
- cmp al,'C' ;is it C or Q?
- je Zdiv3 ;jump, it's a C
- cmp al,'Q'
- je Zdiv2 ;jump, it's a Q
-
- mov dx,offset bad ;illegal entry, send
- mov ah,9 ;a beep, erase the bad char.
- int 21h ;and try again
-
- jmp Zdiv1
-
- Zdiv2: mov ax,4cffh ;user wishes to abort
- int 21h ;program, exit with
- ;return code = 255
-
- Zdiv3: mov dx,offset crlf ;user wishes to continue,
- mov ah,9 ;send carriage ret-line feed
- int 21h
-
- pop es ;restore general registers
- pop ds ;and resume execution
- pop bp
- pop di
- pop si
- pop dx
- pop cx
- pop bx
- pop ax
- iret
-
- Zdiv endp
-
- signon db cr,lf,'Divide by Zero Interrupt '
- db 'Handler installed.'
- db cr,lf,'$'
-
- warn db cr,lf,lf,'Divide by Zero detected: '
- db cr,lf,'Continue or Quit (C/Q) ? '
- db '$'
-
- bad db beep,backsp,' ',backsp,'$'
-
- crlf db cr,lf,'$'
-
- Pgm_Len equ $-Init
-
- cseg ends
-
- end init