王爽.汇编.第三版.实验16.答案

时间:2022-02-22 00:11:03
; int 7c中断例程
;

assume cs:code

code segment

start:
; 拷贝代码
mov ax, 0
mov es, ax
mov ax, 200h
mov di, ax

push cs
pop ds
mov ax, offset int7c
mov si, ax

mov cx, offset int7c_end - offset int7c

cld
rep movsb

cli
mov ax, 0
mov ds, ax
mov bx, 07ch*4
mov word ptr ds:[bx], 200h
mov word ptr ds:[bx+2], 0
sti

mov ax, 4c00h
int 21h

int7c:
jmp short int7c_code
; 注意此处放的是放在绝对地址0:200时,子程序处于的相对地址,
; 此方法不好,因为如果程序不是安装在0:200,就会出错
; 当如如果直接jmp到标号,是没有问题的
table dw sub1-int7c+200h, sub2-int7c+200h
int7c_code:
push ax
push bx

; 功能号
cmp ah, 1
ja int7c_ok
sub bx, bx
mov bl, ah

add bx, bx
push cs
pop ds
; 200是本中断代码的起始地址,2:是jmp指令的长度。bx索引到相应table位置
call word ptr [bx+200h+2]
int7c_ok:
pop bx
pop ax

iret

; clear screen
sub1:
push bx
push cx
push es

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

pop es
pop cx
pop bx

ret
; change text color
sub2:
push bx
push cx
push es

mov bx, 0b800h
mov es, bx
mov bx, 1
mov cx, 2000
sub2s:
and byte ptr es:[bx], 11111000b
or byte ptr es:[bx], al
add bx, 2
loop sub2s

pop es
pop cx
pop bx

ret
suberror:


ret

int7c_end:
nop
code ends

end start