WIPIVERSE All articles

INT 16H

INT 16H (also written as INT 16h, INT 0x16, or INT 22) is shorthand for a BIOS interrupt call numbered 16 in hexadecimal (decimal 22), corresponding to the 23rd interrupt vector in an x86-based computer system. The BIOS typically sets up a real mode interrupt handler at this vector that provides keyboard services.

Overview

INT 16H is a software interrupt used to interface with the keyboard hardware on IBM PC-compatible systems. It is responsible for obtaining basic keyboard functionality, including collecting keystrokes, checking the status of the keyboard buffer, and retrieving the state of modifier keys (such as Shift, Ctrl, and Alt). It operates in real mode and is commonly invoked from assembly language programs or low-level system software.

The interrupt is invoked using the INT assembly instruction with an operand of 16h. The specific function to be performed is selected by placing a value in the AH register before invoking the interrupt.

Services

INT 16H provides a set of subservices, each selected by the value placed in the AH register:

Function AH code Description
Read key press 00h Waits for and reads a keystroke from the keyboard buffer
Get buffer status 01h Checks whether a key is available in the keyboard buffer (non-blocking)
Get shift status 02h Retrieves the current state of Shift, Ctrl, Alt, and other modifier keys
Establish repetition factor 03h Sets the keyboard typematic rate and repeat delay
Keyboard click adjustment 04h Enables or disables the keyboard click sound
Simulate a keystroke 05h Places a synthetic keystroke into the keyboard buffer
Get keyboard ID 0Ah Returns the keyboard identification code
Read expanded key 10h Reads a keystroke from an enhanced (101/102-key) keyboard
Get expanded buffer status 11h Checks buffer status for enhanced keyboards
Get expanded shift status 12h Retrieves modifier key state for enhanced keyboards

Usage Details

The standard encoding provided by INT 16H assumes a US keyboard layout. For international or non-standard keyboards, software must analyze the scan code of the pressed key and perform appropriate interpretation.

For keyboards with 101 keys or more, some keys are interpreted as expanded keys and have scan codes different from those of normal keys (e.g., the Pause key). The functions with codes 10h, 11h, and 12h were added to support these enhanced keyboards.

Return Values

For the primary "read key press" function (AH = 00h), the interrupt returns:

  • AH: the scan code of the key pressed
  • AL: the ASCII character corresponding to the pressed key

For the buffer status function (AH = 01h), the zero flag (ZF) is cleared if a key is available in the buffer and set if no key is available.

Historical Context

INT 16H was introduced as part of the original IBM Personal Computer BIOS in 1981. It forms a core component of the BIOS interrupt architecture and remained a standard interface throughout the era of DOS and real-mode programming. While modern operating systems generally interact with keyboards through device drivers and higher-level abstractions, INT 16H remains documented and understood in the context of legacy systems, embedded development, and hobbyist low-level programming.

Related Concepts

INT 16H is one of several BIOS interrupt calls, alongside INT 10H (video services), INT 13H (disk services), and INT 17H (printer services), which collectively provided standardized hardware access for early x86 software.

Browse

More topics to explore

    Browse all articles