Search code examples
assemblybioskeyboardinterrupt

BIOS and DOS interrupts (16H and 21H)


There are some routines which can be implemented via both INT 21H and INT 16H (former is for DOS and latter is for BIOS). However, the exact difference is not clear (at least for me!).

For example, the following routines read a character from keyboard

1) INT 21H, service 01 for reading with echo

MOV   AH,01
INT   21H

2) INT 16H, service 01 for key press

MOV   AH,01
INT   16H

Assume a program which is waiting for a key. For example, a simple text based wizard which waits for Y/N. For echoing the pressed key, which one is preferred? 21H or 16H.

I can think that BIOS routines should be called when there is no operating system (example is "press F1 to continue" during POST). Is that all? Is there any example, that shows an operation is exclusively done by one of them and not both?


Solution

  • For echoing the pressed key, which one is preferred? 21H or 16H.

    Certainly not the BIOS function since it will not echo anything!

    INT 16H, service 01 for key press

    This function will only check if a key is available. It will not remove it from the keyboard buffer.

    In general you need to be aware that DOS input functions can use re-direction. The input might not come from the keyboard at all. It could come from a file or other source.