I am posting the following piece of code, the basic aim of this code is, when i set the trap flag to 1 then after that i am printing a character z on the screen, now as trap flag is set, the program should execute one instruction and trap, I have written a simple trap ISR in which i have an infinite loop, this infinite loop will be broken if F2 key is pressed as you can see the scan code of F2 key in keyboard isr named kbisr in the program. This is the function that i want to achieve from this program but its not doing it please check this code and tell me what i am doing wrong with it. Here is the code
[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