记录一下代码
assume cs:code
code segment
start:
mov ax,cs
mov ds,ax
mov si,offset do0
mov ax,0
mov es,ax
mov di,200h
mov cx,offset do0end-offset do0
cld
rep movsb ;将ds:si的字节单元byte送入es:di,也就是将从do0处往下的指令复制到0:200h中。
mov word ptr es:[0*4],200h
mov word ptr es:[0*4+2],0
;发生0号中断时,从0*4到0*4+2的两个字单元中读取中断单元处理程序的入口地址,这里设置的两个单元00 02 00 00,即发生0号中断时,跳转到入口地址0000:0200,执行do0往下的程序。
call divide_overflow
;发生溢出时会跳转到do0执行相关指令
mov ax,4c00h
int 21h
divide_overflow:
mov ax,0ffffh
mov bl,1h
div bl
ret
do0:
jmp short do0start
db "divide error!"
do0start:
mov ax,cs ;发生中断时,IP=(N*4),CS=(N*4+2)
mov ds,ax ;此时CS=0000H,IP=0200H
mov si,202h
mov ax,0b800h
mov es,ax
mov di,12*160+36*2
mov cx,13
s:
mov al,[si]
mov es:[di],al
inc si
mov byte ptr es:[di+1],02h
add di,2
loop s
mov ax,4c00h
int 21h
do0end: nop
code ends
end start