I used the int 16h
interrupt, and I want to check if keystroke is available or not.
So I want to check what value the Zero Flag has - how can I do it?
I used the int 16h
interrupt, and I want to check if keystroke is available or not.
So I want to check what value the Zero Flag has - how can I do it?
As you can see here, ZF=1
when there is no keystroke available, and ZF=0
when there is a keystroke available. You can use the J(N)Z
instructions to branch accordingly
Using JZ
:
mov ax, 0100h
int 16h
jz no_key
; Handle case if there is a key press here
; AH will contain the scan code; AL will contain the ASCII code
no_key:
; Handle case if there is no key press here
Using JNZ
:
mov ax, 0100h
int 16h
jnz key_pressed
; Handle case if there is no key press here
key_pressed:
; Handle case if there is a key pressed here
; AH contains the scan code; AL contains the ASCII code