Mov ah,00
int 16
Assembly language programming needs you to be precise.
The BIOS keyboard functions are found at int 16h
. That is 22 in decimal, not the 16 that you wrote! Might not seem a big deal, but it's the difference between success and failure.
MainLoop:
mov ah, 01h ;BIOS.TestKey
int 16h
jz StuffToDoRegardlessOfAnyKey
mov ah, 00h ;BIOS.GetKey
int 16h
cmp al, 27 ;Is it ESCAPE ?
jne ProcessOtherKey
ProcessEscapeKey:
...
...
ProcessOtherKey:
...
...
jmp MainLoop
StuffToDoRegardlessOfAnyKey:
...
...
jmp MainLoop
This is a skeleton program to solve the problem of navigating using the keyboard. On each iteration of the MainLoop it first tests with BIOS keyboard function 01h if there is a key pending.
- If not it does all the stuff that needs to be done regardless of any user input. Refreshing a clock or any information on a status bar would fall in this category.
- If a key is waiting, it is retrieved using BIOS keyboard function 00h. No waiting is involved since we know that a key is available.
- If this key is ESC then the program falls through in ProcessEscapeKey where you can clean up and exit to DOS or whatever you need in this case.
- For any other key it jumps to ProcessOtherKey where you normally will have to differentiate amongst all the different keys that you want to treat. UPDOWNLEFTRIGHT...