我发布了以下代码,这段代码的基本目的是,当我将陷阱标志设置为 1 之后,我在屏幕上打印一个字符 z,现在设置了陷阱标志,程序应该执行一个指令和陷阱,我编写了一个简单的陷阱 ISR,其中我有一个无限循环,如果按下 F2 键,这个无限循环将被打破,因为您可以在程序中看到名为 kbisr 的键盘 isr 中 F2 键的扫描码。这是我想从这个程序中实现的功能,但它没有这样做,请检查这段代码并告诉我我做错了什么。这是代码
[org 0x100]
jmp start
flag: db 0
kbisr: push ax
push cs
pop ds
in al,0x60 ; reading keyboard port
cmp al,60 ; comparing it with scan code of F2
jne skip ; if not F2 then do nothing
mov byte[flag],1
skip: pop ax
; signlaing end of interrupt
mov al,0x20
out 0x20,al
iret
; subroutin to clear the screen
clrscr: push ax
push bx
push es
push di
push cx
mov ax,0xb800
mov es,ax
mov cx,4000
mov ax,0x0720
rep stosw
pop cx
pop di
pop es
pop bx
pop ax
ret
; the trap ISR
trap: push ax
push bx
push cx
push dx
push es
push ss
push ds
push cs
push di
push si
push bp
push cs
pop ds ; initializing the data segment
sti
call clrscr
mov byte[flag],0
l1: cmp byte[flag],0 ; infinite loop, waiting for F2
je l1
pop bp
pop si
pop di
pop cs
pop ds
pop ss
pop es
pop dx
pop cx
pop bx
pop ax
iret
start:
mov ax,0
mov es,ax
; hooking the trap interrupt
mov word[es:1*4],trap
mov word[es:1*4+1],cs
;now hooking the keyboard interrupt
cli
mov word[es:9*4],kbisr
mov word[es:9*4+2],cs
sti
mov cx,0xb800
mov es,cx
mov di,10
mov ch,0x05
mov cl,'z'
;setting the trap flag to 1
pushf
pop bx
or bx,0x100
push bx
popf
; now trap flag is on
mov word[es: di],cx
add di,2
mov word[es: di],cx
add di,2
;residing the program in memory after termination so this is a TSR
mov dx,start
add dx,15
shr dx,4
mov ax,0x3100
int 0x21