Preface: This experiment is experiment 12 (p251) in the third edition of "Assembly Language" written by Mr. Wang Shuang
Experimental environment: DOSBox 0.74-3
Experimental tasks:
Write the handler for interrupt 0 , so that when the division overflow occurs, the string " divide error! " is displayed in the middle of the screen, and then returns to DOS.
Requirements: Carefully track and debug, and do not study the following courses until you understand the whole process.
code:
assume cs:code
code segment
start: ;将do0段代码安装到0000:0200h处
;ds:si指向cs:offset do0
;es:di指向0000:0200h
;代码长度=offset do0end - offset do0start
;传送方向:正向
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
;设置中断向量表
;0号中断对应的中断向量表地址:0000:0000 ~ 0000:0003
;0000:0000字单元存储0000
;0000:0002字单元存储200h
mov ax,0
mov ds,ax
mov word ptr ds:[0],200h
mov word ptr ds:[2],0h
;除法溢出测试
mov ax,1000
mov bh,1
div bh
mov ax,4c00h
int 21h
do0: jmp short do0start
db "divide error!"
do0start: mov ax,0b800h
mov es,ax
mov di,12*160+36*2 ;设置es:di指向显示的显示缓存单元
mov ax,cs
mov ds,ax ;字符串和代码数据都在一个段内:cs段
mov si,202h ;ds:si指向显示的字符串
mov cx,13 ;设置字符串长度
s: mov al,ds:[si]
mov es:[di],al
mov al,01000010b
mov es:[di+1],al
inc si
add di,2
loop s
mov ax,4c00h
int 21h
do0end: nop
code ends
end start
operation result: