8086 Interrupt Table: INT 10h, INT 16h and INT 21h Explained

An interrupt is a detour with a return address. When a program executes INT n, the processor saves the flags, the code segment and the instruction pointer, looks up entry n in the interrupt vector table, and jumps to the handler it finds there. When the handler finishes with IRET, execution resumes exactly where it left off. INT 10h, INT 16h and INT 21h are the three software interrupts students meet first, because they cover the screen, the keyboard and DOS.

The interrupt vector table

The table lives at the very start of memory, from address 0000:0000 to 0000:03FFh. It has 256 entries, one for each interrupt number from 0 to 255, and each entry is four bytes: a 16-bit offset followed by a 16-bit segment, giving the full address of the handler. Entry n therefore sits at address n times 4. INT 21h uses entry 21h, which is at 0000:0084h; INT 10h uses entry 10h, at 0000:0040h; INT 16h uses entry 16h, at 0000:0058h. A program can read these entries, and advanced programs can replace them to install their own handlers, but ordinary student code simply calls the handlers that DOS and the BIOS already installed.

INT 10h: video services

AH Function Key registers
00h Set video mode Mode number in AL; mode 03h is the standard 80 by 25 text mode and clears the screen.
02h Set cursor position Page in BH, row in DH, column in DL.
0Eh Teletype output Character in AL, page in BH; advances the cursor, honouring carriage return and line feed.
13h Write a string String in ES:BP, length in CX, position in DH/DL, attribute in BL.

INT 16h: keyboard services

AH Function Result
00h Read a keystroke, waiting ASCII code in AL, scan code in AH; waits until a key is pressed.
01h Check for a keystroke ZF set if no key is waiting; otherwise AL and AH hold the key without removing it from the buffer.
02h Get shift flags AL reports the state of Shift, Ctrl, Alt and the lock keys.

The difference between INT 16h function 00h and function 01h is the difference between a program that waits and a program that polls. A game loop checks with function 01h and keeps animating when no key is waiting; a menu reads with function 00h and simply waits.

INT 21h: DOS services

INT 21h is covered in depth in its own post, but the summary belongs here: AH selects a DOS function, with 02h writing a character, 09h printing a ‘$’-terminated string, 01h reading a character with echo, and 4Ch exiting the program. The pattern, function number in AH and parameters in the other registers, is the same pattern INT 10h and INT 16h use, which is why learning one interrupt teaches the shape of all three.

Worked example: clear the screen, print, wait for a key

ORG 100h

MOV AX, 0003h        ; INT 10h, AH=00h: video mode 03h, clears screen
INT 10h

LEA DX, message
MOV AH, 09h          ; INT 21h, AH=09h: print the string
INT 21h

MOV AH, 00h          ; INT 16h, AH=00h: wait for a keypress
INT 16h

MOV AX, 4C00h        ; INT 21h, AH=4Ch: exit
INT 21h

message DB 'Press any key to exit.', 0Dh, 0Ah, '$'
RET

Choosing between the three

  • Use INT 21h for ordinary console input and output and for files.
  • Use INT 10h when you need the screen itself: clearing it, moving the cursor, or writing at a position.
  • Use INT 16h when you need keyboard behaviour DOS does not offer, such as polling without blocking, or reading scan codes for keys that have no ASCII code.

All three go through the same vector table, all three are selected by AH, and all three return through IRET to the instruction after the INT. Once that shape is clear, the rest is looking up the right function number.

Further reading

New to assembly? Start with Your First 8086 Program: Hello World, then return here.

Similar Posts