| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 
 | ; 自定义0号中断处理程序assume cs:code
 code segment
 start:
 mov ax,cs
 mov ds,ax
 mov si,offset do0       ; ds:si指向中断程序代码的开始地址
 mov ax,0
 mov es,ax
 mov di,200h              ; es:di指向中断程序存放处开始地址
 mov cx,offset do0end - offset do0   ; 计算中断程序长度
 cld                             ; 设置串传送方向为正
 rep movsb                 ; 串传送,把中断程序代码复制到0:200h处
 
 ; 设置中断向量
 mov ax,0
 mov es,ax
 mov word ptr es:[0*4],200h
 mov word ptr es:[0*4+2],0
 
 mov ax,4c00h
 int 21h
 
 do0:
 jmp short do0start     ; jmp指令长2字节
 db "divide error!"      ; 显示内容放在中断程序自身内部
 
 do0start:
 mov ax,cs                ; 中断程序装载到0:200h后,被调用时,cs=0,ip=200
 mov ds,ax
 mov si,202h            ; ds:si指向中断程序中的字符串的开头
 
 mov ax,0b800h
 mov es,ax
 mov di,12*160+36*2     ; es:di指向显存空间中间,即屏幕中间位置
 
 mov ah,00000100b       ; 设为红色字
 mov cx,13                      ; 字符串长度13
 s:
 mov al,[si]
 mov es:[di],ax
 inc si
 add di,2
 loop s
 
 mov ax,4c00h           ; 中断程序中包含退出,执行中断程序后返回到系统
 int 21h
 
 do0end:
 nop                    ; 填充一个空字节,为了让do0end参与计算中断程序长度
 
 code ends
 end start
 
 |