实验

安装新的int 9 中断例程

安装一个新的int 9中断例程,功能:在DOS下,按下“A”键后,除非不松开,如果松开,就显示满屏幕的“A”,其他的键照常处理。
1
2
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
54
55
56
57
58
59
60
61
62
63
64
65
66
assume cs:code

code segment
start:
sli ;防止在设置中断向量表之前出现有键盘输入导致错误
mov ax, cs
mov ds, ax
mov si, offset int9

mov ax, 0
mov es, ax
mov di, 204h ;[200]与[202]要存放原int 9的IP和CS

mov cx, offset int9_end - offset int9
cld ;正向复制

rep movsb

mov ax, es:[9*4]
mov es:[200h], ax
mov ax, es:[9*4+2]
mov es:[202h], ax ;保存原int 9中断例程入口地址

mov word ptr es:[9*4], 204h
mov word ptr es:[9*4+2], 0 ;设置中断向量表
sti ;IF设置1

mov ax, 4c00h
int 21h

----------------------int9-------------------------
int9:
push ds
push ax
push cx
push si

in al, 60h ;接受60h来的扫描码
pushf
call dword ptr cs:[200h]

cmp al, 1eh+80h ;A是否被松开
jne int9_ok ;不是松开正常处理

mov ax, 0b800h
mov ds, ax
mov si, 0
mov cx, 2000 ;打满一屏是2000个字符

print_char:
mov byte ptr [si], 'A'
add si, 2
loop print_char

int9_ok:
pop si
pop cx
pop ax
pop ds
iret

int9_end:
nop

code ends
end start