# 编程处理0号中断

小编也是最近学习到中断知识,学到如何创建0号中断.

0号中断属于除法溢出中断.当CPU处理程序时,发生除法溢出错误,间产生中断类型码为0的中断信息,然后根据中断向量表查找到IP,CS地址,进而转去执行相应的中断程序.

过程为:

(1) 取得中断类型吗

(2) pushf(标志寄存器入栈)

(3) TF(防止陷入单步中断循环),IF置0.

(4)CS入栈

(5)IP入栈

(1) 编写可以显示"overflow!"的中断处理程序:do0;

(2)将do0送入内存0000:0200处;

(3) 境do0的入口地址0000:0200存储在中断向量表的-号表项中.

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,DO0 OFFSET DO0END-OFFSET DO0;代码长度
CLD
REP MOVSB
设置中断向量表
MOV AX,4CH
INT 21H

DO0:

DO0END:NOP
CODE ENDS
END START

DO0的主要任务就是显示字符串:

DO0:设置ds:si指向字符串
MOV AX,0B800H
MOV ES,AX
MOV DI,12*160+36*2

MOV CX,9
S:MOV AL,[SI]
MOV ES:[DI],AL
INC SI
LOOP S

MOV AH,4CH
INT 21H

DO0END:NOP
CODE ENDS
END START

DO0:jmp SHORT DO0START
DB "OVERFLOW !","$" DO0START:MOV AX,CS MOV DS,AX MOV SI,202H ;设置es:di指向显存空间的中间位置 接下里,设置中断向量: 将do0的入口地址0:200写入到中断向量表中,使得do成为0号中断处理程序. 0:0存放偏移地址,0:2存放段地址. MOV AX,0 MOV ES,AX MOV WORD PTR ES:[0*4],200H MOV WORD PTR ES:[0*4+2],0 MOV AX,4CH INT 21H 完整代码: 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,DO0 OFFSET DO0END-OFFSET DO0;代码长度 CLD REP MOVSB MOV AX,0 MOV ES,AX MOV WORD PTR ES:[0*4],200H MOV WORD PTR ES:[0*4+2],0 MOV AX,4CH INT 21H DO0:jmp SHORT DO0START DB "OVERFLOW !","$"
DO0START:MOV AX,CS
MOV DS,AX
MOV SI,202H
MOV AX,0B800H
MOV ES,AX
MOV DI,12*160+36*2

MOV CX,9
S:MOV AL,[SI]
MOV ES:[DI],AL
INC SI
END START