;学习来自:汇编语言-王爽(第四版)。第15章:外中断
assume cs:codeseg,ds:dataseg ,ss:stackseg
dataseg segment
;保存原int9的初始地址,每个地址大小为2字节
dw 0,0
dataseg ends
stackseg segment
;入栈用的空间
db 128 dup (0)
stackseg ends
codeseg segment
main:
;初始化寄存器ds,ss,es
mov ax,dataseg
mov ds,ax
mov ax,stackseg
mov ss,ax
mov ax,0h
mov es,ax
;保存int9的初始地址
mov ax,word ptr es:[24h];
mov word ptr ds:[0h],ax
mov ax,word ptr es:[26h]
mov word ptr ds:[2h],ax
;设置新int9的初始地址
mov word ptr es:[24h],offset my_int9
mov word ptr es:[26h],codeseg
;显示字符
mov ax,0b800h
mov es,ax
mov ah,'a'
show_char:
mov byte ptr es:[07b0h],ah
call stop_10;调用循环停留
inc ah
cmp ah,'z'
jna show_char
;还原原int9中断处理程序初始地址
mov ax,0h
mov es ,ax
mov ax,word ptr ds:[0h]
mov word ptr es:[24h],ax
mov ax,word ptr ds:[2h]
mov word ptr es:[26h],ax
mov ax,4c00h;设置ah中断子程序
int 21h;中断
;循环停留
stop_10:
push ax
push bx
mov ax,0h
mov bx,10h
s:
sub ax,1h;ffffffff减去直到为0
sbb bx,0h;减去10次借位直到为0
cmp ax,0h
jne s
cmp bx,0h
jne s
pop bx
pop ax
ret
;新中断处理程序
my_int9:;按一下 esc键 中间文字的颜色变化
push ax
push bx
push es
;读端口60h
in al,60h;获取中断信息
;所有标志寄存器入栈
pushf
;修改if,tf=0
pushf
pop bx
and bx,11111100b
push bx
popf
;调用原中断处理程序
call dword ptr ds:[0h]
cmp al,1
jne my_int9_end
mov ax,0b800h
mov es,ax
inc byte ptr es:[07b1h];属性加一
my_int9_end:
pop es
pop bx
pop ax
iret;中断退出
codeseg ends
end main