assume cs:code
code segment
start:
;保存原来的中断入口
mov ax,0
mov es,ax
mov ax,es:[94]
mov es:[200h],ax
mov ax,es:[94+2]
mov es:[202h],ax
;将自己编写的中断程序送入0:204h
mov ax,cs
mov ds,ax
mov si,offset int9
mov di,204h
mov cx,offset int9_end - offset int9
cld
rep movsb
;修改中断向量表(不加cli sti的话万一在修改中断向量表的途中发生了中断就会引发错误)
cli
mov word ptr es:[9*4],204h
mov word ptr es:[9*4+2],0
sti
;在屏幕中间显示'a'-'z'
mov ax,0b800h
mov es,ax
mov ah,'a'
display:
mov es:[160*12+40*2],ah
call delay
inc ah
cmp ah,'z'
jna display
;将原来的中断入口装回以方便下次继续使用
cli
mov ax,0
mov es,ax
mov ax,es:[200h]
mov es:[9*4],ax
mov ax,es:[202h]
mov es:[9*4+2],ax
sti
mov ax,4c00h
int 21h
;手动延迟
delay:
push ax
push dx
mov dx,4h
mov ax,0
delay_s:
sub ax,1
sbb dx,0
cmp ax,0
jne delay_s
cmp dx,0
jne delay_s
pop dx
pop ax
ret
;自己的中断处理程序
int9:
push ax
push bx
push es
;1.读取60h端口中的输入
in al,60h
;2.调用原始的int9 中断处理我们处理不了的细节
;a.取中断类型码
;b.标志寄存器入栈,IF = 0,TF = 0
pushf
pushf
pop ax
and ah,11111100b
push ax
popf
;c.cs,ip入栈
;d.IP = n*4,CS = n*4+2
mov bx,0
mov es,bx
call dword ptr es:[200h]
;3.看看是不是ESC键,如果是,就改变颜色
cmp al,01h
jne int9_ret
mov bx,0b800h
mov es,bx
inc byte ptr es:[160*12+40*2+1]
int9_ret:
pop es
pop bx
pop ax
iret
int9_end:
nop
code ends
end start
自己敲的代码,运行按下ESC不会改变颜色,不知道哪错了。。。。。