Interrupt Services: INT 21H and INT 10H
Open in the Padhaiko app3.12 Interrupt services: INT 21H and INT 10H
In 8086 MS-DOS systems, application programs rarely program keyboard controllers or video RAM hardware directly. Instead, they invoke built-in software interrupts using the INT n instruction. By convention, the caller loads a function number into AH and arguments into AL, BX, CX, DX, or DS:DX before executing INT.
| Aspect | DOS Interrupt (INT 21H) | BIOS Video Interrupt (INT 10H) |
|---|---|---|
| Provider Layer | MS-DOS operating system kernel | Motherboard / Video card ROM-BIOS |
| Primary Scope | Keyboard I/O, console text output, file/directory I/O, memory, program exit | Video modes, cursor positioning, window scrolling, screen clearing, colored text/pixels |
| Portability / Redirection | Supports DOS standard input/output redirection (<, >) | Talks directly to display hardware/video buffer (no DOS redirection) |
| String Terminator | AH = 09H requires trailing '\$' (24H) | Prints exact character count in CX (AH = 09H/0AH) or single char in AL (AH = 0EH) |
DOS Function Calls (INT 21H)
AH | Service Name | Input Registers | Output / Behaviour |
|---|---|---|---|
01H | Keyboard Input with Echo | None | Waits for key; echoes character to screen; returns ASCII in AL (checks Ctrl-C). |
02H | Display Single Character | DL = ASCII character | Prints character in DL at current cursor and advances cursor. |
07H | Direct Console Input (No Echo) | None | Reads key without echo and without Ctrl-C check; ASCII in AL. |
08H | Console Input (No Echo) | None | Reads key without echo; checks Ctrl-C; ASCII in AL. |
09H | Display String | DS:DX = address of string | Prints characters from DS:DX up to (excluding) '\$' (24H). |
0AH | Buffered Keyboard Input | DS:DX = address of input buffer | Reads line up to Enter (0DH) into buffer; stores actual count in byte [1]. |
4CH | Terminate Program | AL = return code (usually 00H) | Closes open handles and returns control cleanly to DOS. |
Buffered String Input Structure (INT 21H, AH = 0AH)
Before calling INT 21H with AH = 0AH, the program must reserve a buffer in .DATA whose layout is:
- Byte 0 (
[BUF + 0]): Maximum number of characters allowed, including the final Carriage Return (0DH). Set by the programmer (1to255). - Byte 1 (
[BUF + 1]): Actual number of characters typed by the user, excluding0DH. Filled in by DOS afterEnteris pressed. - Bytes 2 onward (
[BUF + 2 ...]): The typed ASCII characters, terminated automatically by0DH(Enter).
Example declaration: BUF DB 20, ?, 20 DUP(?) (or named fields MAXLEN DB 20, ACTLEN DB ?, CHARS DB 20 DUP(?)).
BIOS Video Services (INT 10H)
AH | Service Name | Input Registers | Output / Effect |
|---|---|---|---|
00H | Set Video Mode | AL = mode (03H = 80x25 16-color text) | Switches mode and clears the entire screen. |
01H | Set Cursor Shape | CH = start scan line, CL = end scan line | Changes cursor thickness (bits 5–6 of CH hide cursor when 01). |
02H | Set Cursor Position | BH = page (0), DH = row (0–24), DL = col (0–79) | Moves text cursor to (row, col). |
03H | Read Cursor Position | BH = display page (0) | Returns DH = row, DL = col, CH/CL = cursor scan lines. |
06H | Scroll Window Up / Clear | AL = lines (0 = clear all), BH = attribute, CH,CL = top-left, DH,DL = bottom-right | Scrolls window up or clears rectangular region to color attribute in BH. |
07H | Scroll Window Down | Same as 06H | Scrolls window downward by AL lines (0 clears window). |
09H | Write Char & Attribute | AL = char, BH = page, BL = attribute, CX = repeat count | Displays char CX times at cursor without advancing cursor. |
0EH | Teletype Output | AL = char, BH = page | Prints char and advances cursor (interprets 0DH, 0AH, 08H). |
1
Write an 8086 assembly program that clears the full 80x25 screen with bright-yellow text on a blue background (1EH) using INT 10H, moves the cursor to row 12, column 34, and displays "Institute of Engineering 8086 LAB" using INT 21H.
Setting Screen Coordinates & Attribute Registers:
- Attribute byte for non-blinking (
0), blue background (001), intense (1), yellow foreground (110):0001 1110B = 1EH. - Cursor position
(row=12, col=34)in hex:DH = 0CH,DL = 22H, soDX = 0C22H.
Complete 8086 Program:
.MODEL SMALL
.STACK 100H
.DATA
MSG DB 'Institute of Engineering 8086 LAB$'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
; 1. Clear full screen (rows 0..24, cols 0..79) with attribute 1EH
MOV AH, 06H ; BIOS Scroll Up / Clear Window
MOV AL, 00H ; 00H = clear entire window
MOV BH, 1EH ; Yellow (EH) on Blue (1H)
MOV CX, 0000H ; Top-left: row 0, col 0
MOV DX, 184FH ; Bottom-right: row 24 (18H), col 79 (4FH)
INT 10H
; 2. Position cursor at row 12 (0CH), col 34 (22H)
MOV AH, 02H ; BIOS Set Cursor Position
MOV BH, 00H ; Display page 0
MOV DH, 12 ; Row 12 (0CH)
MOV DL, 34 ; Column 34 (22H)
INT 10H
; 3. Print string using DOS INT 21H AH=09H
LEA DX, MSG
MOV AH, 09H
INT 21H
; 4. Exit to DOS
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAININT 10H AH=06H (AL=00H, BH=1EH, CX=0000H, DX=184FH) clears the screen in yellow-on-blue, INT 10H AH=02H (BH=00H, DH=0CH, DL=22H) places the cursor at (12, 34), and INT 21H AH=09H prints 'Institute of Engineering 8086 LAB\$'.
2
Write an 8086 program to read a string (up to 19 characters) from the user via INT 21H AH=0AH, replace the trailing 0DH with '\$' (24H), and display it back on a new line. Also trace the buffer bytes in memory if the user types Institute of Engineering and presses Enter.
Tracing BUF Memory Layout for Input "Institute of Engineering" + Enter: Declare MAX DB 20, ACT DB ?, STR_DATA DB 20 DUP(?).
- Before call:
[BUF+0] = 14H(20). - After typing
Institute of Engineering+ Enter: DOS sets[BUF+1] = 03H(ACT = 3),[BUF+2] = 'I' (49H),[BUF+3] = 'O' (4FH),[BUF+4] = 'E' (45H),[BUF+5] = 0DH(CR). - To print with
AH = 09H, we indexSTR_DATA[BX]whereBX = ACT = 0003Hand overwrite0DHatBUF+5with'\$'(24H).
Complete Program:
.MODEL SMALL
.STACK 100H
.DATA
NEWLINE DB 0DH, 0AH, '$'
BUF DB 20 ; Byte 0: Max characters (including CR)
ACT_LEN DB ? ; Byte 1: Actual characters typed
TXT DB 20 DUP(?) ; Byte 2+: Characters + CR (0DH)
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
; 1. Read buffered string from keyboard
LEA DX, BUF
MOV AH, 0AH
INT 21H
; 2. Append '$' terminator right after last typed character
MOV BL, ACT_LEN ; BL = actual count (3 for "Institute of Engineering")
MOV BH, 00H ; BX = 0003H
MOV TXT[BX], '$' ; Replace 0DH with '$' (24H)
; 3. Print CR+LF then user string
LEA DX, NEWLINE
MOV AH, 09H
INT 21H
LEA DX, TXT
MOV AH, 09H
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAININT 21H AH=0AH fills ACT_LEN = 03H and TXT = 'I','O','E',0DH; indexing TXT[BX] with BX = ACT_LEN replaces 0DH at BUF+5 with 24H ('\$'), allowing INT 21H AH=09H to display "Institute of Engineering".
3
Trace a program that reads a single lowercase letter silently via INT 21H AH=08H, converts it to uppercase, and prints it via INT 21H AH=02H. Show register states if the user presses 'm' (6DH).
ASCII Lowercase-to-Uppercase Conversion: Lowercase 'a'–'z' occupy ASCII 61H–7AH, while uppercase 'A'–'Z' occupy 41H–5AH—an exact difference of 20H (32). Checking AL >= 'a' and AL <= 'z' and subtracting 20H converts 'm' (6DH) to 'M' (4DH).
Program & Register Trace:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 08H ; Read key without echo -> AL
INT 21H
CMP AL, 'a'
JB PRINT_CH
CMP AL, 'z'
JA PRINT_CH
SUB AL, 20H ; Convert lowercase to uppercase
PRINT_CH:
MOV DL, AL ; AH=02H prints character in DL
MOV AH, 02H
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAINAH = 08H returns AL = 6DH ('m') without echoing it; SUB AL, 20H yields 4DH ('M'), which is copied to DL and printed by INT 21H AH = 02H.
Exercises
Distinguish between DOS interrupt INT 21H and BIOS video interrupt INT 10H, and summarize five commonly used INT 21H functions with their AH values and register conventions.
DOS INT 21H vs. BIOS INT 10H:
INT 21Hprovides OS-level services (console I/O, files, program termination) that support DOS redirection.INT 10Hprovides lower-level ROM-BIOS display control (video mode, cursor row/col, window scrolling, color attributes).
Five INT 21H Functions:
AH = 01H: Read character with echo -> returns ASCII inAL.AH = 02H: Display single character -> takes ASCII inDL.AH = 09H: Print'\$'-terminated string -> takes string offset inDS:DX.AH = 0AH: Buffered line input -> takes buffer offset inDS:DX.AH = 4CH: Exit program -> takes exit code inAL.
INT 21H handles OS-level I/O and termination (01H, 02H, 09H, 0AH, 4CH), whereas INT 10H controls hardware-level video modes, cursor placement, scrolling, and attributes.
Explain the 3-part buffer layout required by INT 21H AH=0AH. If BUF DB 15, ?, 15 DUP(?) is used and the user types 8086 followed by Enter, give the hexadecimal value stored in each of the first 7 bytes of BUF.
Buffer Structure:
- Byte 0: Maximum allowed characters including CR (
15 = 0FH). - Byte 1: Actual characters typed excluding CR (
4 = 04Hfor"8086"). - Bytes 2+: ASCII characters
'8'(38H),'0'(30H),'8'(38H),'6'(36H), followed by Carriage Return0DH.
First 7 Bytes of BUF:
[BUF+0] = 0FH(15)[BUF+1] = 04H(4)[BUF+2] = 38H('8')[BUF+3] = 30H('0')[BUF+4] = 38H('8')[BUF+5] = 36H('6')[BUF+6] = 0DH(CR)
Bytes 0..6 contain 0FH, 04H, 38H, 30H, 38H, 36H, 0DH.
Write an 8086 assembly program that uses INT 10H to clear the entire screen with white text on a blue background (17H), positions the cursor at row 10, column 25, and prints "WELCOME" using INT 21H.
Attribute and Coordinate Values:
- Blue background (
001B) + non-blinking (0B) + normal white foreground (0111B) =0001 0111B = 17H. - Row
10 = 0AH, Column25 = 19H->DX = 0A19H.
Complete Program:
.MODEL SMALL
.STACK 100H
.DATA
MSG DB 'WELCOME$'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
MOV AH, 06H ; Scroll up / clear screen
MOV AL, 00H
MOV BH, 17H ; White on blue attribute
MOV CX, 0000H ; (0,0)
MOV DX, 184FH ; (24,79)
INT 10H
MOV AH, 02H ; Set cursor position
MOV BH, 00H
MOV DH, 10 ; Row 10 (0AH)
MOV DL, 25 ; Col 25 (19H)
INT 10H
LEA DX, MSG
MOV AH, 09H ; Print string
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAINUse INT 10H AH=06H (AL=00H, BH=17H, CX=0000H, DX=184FH), INT 10H AH=02H (BH=00H, DH=0AH, DL=19H), and INT 21H AH=09H with DX = OFFSET MSG.
Compare INT 21H functions AH = 01H, AH = 07H, and AH = 08H for keyboard input, and explain when you would choose INT 10H AH = 09H instead of INT 21H AH = 02H for displaying a character.
Keyboard Input Functions (01H, 07H, 08H):
AH = 01H: Echoes the typed character on screen and checksCtrl-C/Ctrl-Break.AH = 08H: Suppresses screen echo (useful for passwords/menus) while still checkingCtrl-C.AH = 07H: Suppresses both screen echo andCtrl-Chandling (raw binary/control key capture).
INT 10H AH = 09H vs. INT 21H AH = 02H: INT 21H AH = 02H prints a single character using the existing screen attribute and advances the cursor. INT 10H AH = 09H lets you specify both a custom color attribute (BL) and a repeat count (CX) to draw colored characters or repeated symbols (e.g., horizontal bars) without advancing the cursor.
01H echoes and checks Ctrl-C, 08H hides echo and checks Ctrl-C, and 07H hides echo without checking Ctrl-C. Choose INT 10H AH=09H over INT 21H AH=02H when you need custom color attributes (BL) or repeated character output (CX).
Calculate the 8-bit video attribute byte for a blinking, bright-red foreground on a cyan (blue + green) background, and show the INT 10H register values to print 'X' 5 times at the current cursor with that attribute on page 0.
Constructing the Attribute Byte:
- Bit 7 (Blink) =
1 - Bits 6–4 (Background Cyan = Red 0, Green 1, Blue 1) =
011 - Bit 3 (Intensity = Bright) =
1 - Bits 2–0 (Foreground Red = Red 1, Green 0, Blue 0) =
100
Combining bits 7..0: 1 011 1 100B = 1011 1100B = BCH.
INT 10H Register Setup: Invoke INT 10H with AH = 09H, AL = 'X' (58H), BH = 00H (page 0), BL = BCH, and CX = 0005H.
Attribute byte is BCH (1011 1100B); call INT 10H with AH=09H, AL='X', BH=00H, BL=BCH, CX=0005H.