hooking divide by zero interrupt assembly language programming
; hooking divide by zero interrupt
[org 0x0100]
jmp start
message: db ' overflow error ', 0
clrscr:
push es
push ax
push cx
push di
mov ax, 0xb800
mov es, ax ; point es to video base
xor di, di ; point di to top left column
mov ax, 0x0720 ; space char in normal attribute
mov cx, 2000 ; number of screen locations
cld ; auto increment mode
rep stosw ; clear the whole screen
pop di
pop cx
pop ax
pop es
ret
; terminated string as parameters
printstr:
push si
push di
push ax
mov si,0
mov ax,0xb800
mov es,ax
mov ah,0x07
redoit:
mov di,0
prt:
mov al,[message+di]
cmp al,0
je nextt
mov [es:si],ax
add si,2
jmp redoit
nextt
pop ax
pop di
pop si
ret
myisrfor0:
push ax ; push all regs
push bx
push cx
push dx
push si
push di
push bp
push ds
push es
push cs
pop ds ; point ds to our data segment
call clrscr ; clear the screen
push ds
mov ax, message
push ax ; push offset of message
call printstr ; print message
pop es
pop ds
pop bp
pop di
pop si
pop dx
pop cx
pop bx
pop ax
iret ; return from interrupt
; subroutine to generate a divide by zero interrupt
genint0:
mov ax, 0x8432 ; load a big number in ax
mov bl, 2 ; use a very small divisor
div bl ; interrupt 0 will be generated
ret
start: xor ax, ax
mov es, ax ; load zero in es
mov word [es:0*4], myisrfor0 ; store offset at n*4
mov [es:0*4+2], cs ; store segment at n*4+2
call genint0 ; generate interrupt 0
mov ax, 0x4c00 ; terminate program
int 0x21
[org 0x0100]
jmp start
message: db ' overflow error ', 0
clrscr:
push es
push ax
push cx
push di
mov ax, 0xb800
mov es, ax ; point es to video base
xor di, di ; point di to top left column
mov ax, 0x0720 ; space char in normal attribute
mov cx, 2000 ; number of screen locations
cld ; auto increment mode
rep stosw ; clear the whole screen
pop di
pop cx
pop ax
pop es
ret
; terminated string as parameters
printstr:
push si
push di
push ax
mov si,0
mov ax,0xb800
mov es,ax
mov ah,0x07
redoit:
mov di,0
prt:
mov al,[message+di]
cmp al,0
je nextt
mov [es:si],ax
add si,2
jmp redoit
nextt
pop ax
pop di
pop si
ret
myisrfor0:
push ax ; push all regs
push bx
push cx
push dx
push si
push di
push bp
push ds
push es
push cs
pop ds ; point ds to our data segment
call clrscr ; clear the screen
push ds
mov ax, message
push ax ; push offset of message
call printstr ; print message
pop es
pop ds
pop bp
pop di
pop si
pop dx
pop cx
pop bx
pop ax
iret ; return from interrupt
; subroutine to generate a divide by zero interrupt
genint0:
mov ax, 0x8432 ; load a big number in ax
mov bl, 2 ; use a very small divisor
div bl ; interrupt 0 will be generated
ret
start: xor ax, ax
mov es, ax ; load zero in es
mov word [es:0*4], myisrfor0 ; store offset at n*4
mov [es:0*4+2], cs ; store segment at n*4+2
call genint0 ; generate interrupt 0
mov ax, 0x4c00 ; terminate program
int 0x21
Comments
Post a Comment