解:
assume cs:code
stack segment
db 128 dup(0)
stack ends
code segment
start:
mov ax,stack
mov ss,ax
mov sp,128
push cs
pop ds ;令ds = cs
mov ax,0
mov es,ax ;令es = 0
mov si,offset int9
mov di, 204h
mov cx,offset int9end - offset int9
cld
rep movsb ;把int9安装到了 0:204
push es:[9*4]
pop es:[200h]
push es:[9*4+2]
pop es:[202h] ;把原本int9的入口保存在了0:200,0:202
cli
mov word ptr es:[9*4],204h
mov word ptr es:[9*4+2],0 ;设置9号中断的入口为0:204
sti
mov ax,4c00h
int 21h
int9:
push ax
push bx
push cx
push es
in al,60h ; 从60h端口读入
mov bx,0
mov es,bx
pushf
call dword ptr es:[200h] ;在0:200的位置读取CS,IP,运行原本的int9
cmp al,9EH
jne int9ret
mov ax,0b800h
mov es,ax
mov bx,0
mov cx,2000
s:
mov byte ptr es:[bx],41H
add bx,2
loop s
int9ret:
pop es
pop cx
pop bx
pop ax
iret
int9end:
nop
code ends
end start
实验结果: