王爽《汇编语言》(第三版)实验15解析

安装新的 int 9 中断例程
安装一个新的 int 9 中断例程,功能: 在DOS下,按下“A”键后,除非不再松开,如果松开,就显示满屏幕的“A”,其他的键照常处理。
提示:断码=通码+80H

代码如下

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
67
68
69
 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

mov ax,0
mov es,ax

mov si,offset int9
mov di,204h ; 设置es:di指向目的地址
mov cx,offset int9end-offset int9 ; 设置cx为传输长度
cld ; 正方向传输
rep movsb

push es:[9*4]
pop es:[200h]
push es:[9*4+2]
pop es:[202h]

cli
mov word ptr es:[9*4],204h
mov word ptr es:[9*4+2],0
sti

mov ax,4c00h
int 21h

int9:
push ax
push bx
push cx
push es

in al,60h

pushf
call dword ptr cs:[200h] ; 当此中断例程执行时(CS)=0

cmp al,1Eh+80h ; ‘A’的断码为1eh+80h
jne int9ret

mov ax,0b800h
mov es,ax
mov bx,0
mov cx,2000
s: mov byte ptr es:[bx],'A'
add bx,2
loop s

int9ret:
pop es
pop cx
pop bx
pop ax
iret
int9end:
nop

code ends
end start