DOS Function Calls

INT 21h, character input/output, string display.

Mohith N
Updated: 19 March 2026
9 min read

DOS function calls provide a standardized software interface between assembly language programs and the operating system, allowing programs to perform input, output, file management, and process control without directly accessing hardware. In the 8086 programming context, all DOS services are accessed through the INT 21h instruction, where the function number is loaded into the AH register before executing the interrupt. Mastering INT 21h is essential for 8086 assembly lab work and practical examinations.

INT 21h DOS Function Calls OverviewLoad AH = Function NumberLoad other registers as requiredExecute INT 21hDOS dispatches to correct service handlerResult returned in AX / AL / DXCommon FunctionsAH=01h: Read char (echo)AH=02h: Display charAH=08h: Read char (no echo)AH=09h: Display stringAH=0Ah: Buffered inputAH=4Ch: Terminate programRegister SetupAH = function numberAH=02h: DL = charAH=09h: DX = string addrAH=0Ah: DX = buffer addrAH=4Ch: AL = exit codeAH=01h: result in ALString for AH=09h must end with '$' (24h)DOS scans memory from DS:DX until it finds a '$' and prints all characters before it.The '$' terminator is NOT printed on screen.
Figure 1: INT 21h DOS function call mechanism showing register setup, dispatch, and common service functions

Core Concept Explanation

DOS function calls are software interrupts that use the INT 21h vector. The programmer places the desired function number in register AH before executing INT 21h. DOS reads AH and routes the call to the appropriate internal routine. Additional parameters are passed through other registers as specified by each function. This design means a single interrupt vector (21h) serves as a gateway to over 100 different OS services, making it a clean and modular interface.

Function 01h reads a single character from standard input (keyboard) and echoes it to the screen, returning the ASCII code in AL. Function 02h displays the character in DL on the standard output (screen). Function 08h reads a character without echo, useful for password input. These three functions handle the most basic character-level I/O in 8086 assembly programs.

Function 09h displays a string stored in memory starting at the address in DS:DX. The string must be terminated with the '$' character (ASCII 24h). DOS continues printing characters from DS:DX until it encounters '$', which itself is not displayed. This means the dollar sign cannot appear in the output string, a limitation of DOS function 09h. Function 4Ch terminates the program and returns control to DOS, with the exit code in AL.

Buffered Input with Function 0Ah

Function 0Ah provides buffered keyboard input. The programmer must create a buffer in memory and pass its address in DS:DX. The buffer structure requires the first byte to hold the maximum number of characters allowed (including the carriage return). The second byte is filled by DOS with the actual number of characters entered. The input string starting from the third byte includes the carriage return (0Dh) at the end but does not include a null terminator. This function is the closest equivalent to gets() in C and is used in programs requiring line-by-line input.

Mathematical Expression

There is no complex mathematical formula involved in DOS function calls, but the buffer layout for function 0Ah can be expressed precisely. If the buffer starts at address B, then: B[0] = max characters (programmer sets this), B[1] = actual characters entered (DOS fills this after INT 21h), B[2] through B[2 + B[1] - 1] = the actual input characters, B[2 + B[1]] = 0Dh (carriage return). The minimum buffer size required is B[0] + 2 bytes.

Practical Understanding

In assembly programming labs, most programs follow a standard pattern: use AH=09h to display a prompt string, use AH=01h or AH=0Ah to read user input, process the input using arithmetic or logic instructions, display the result using AH=02h or AH=09h, and finally terminate using AH=4Ch. This sequence mirrors the standard input-process-output model taught in structured programming.

One important practical detail is that function 02h only displays a single character (the value in DL). To display a multi-digit number, the programmer must convert the binary value to its ASCII digit characters manually, typically by repeated division by 10, and then display each digit using AH=02h in a loop. This conversion process is a very common practical and university examination task.

Solved Numerical Example

A buffer is defined for AH=0Ah input with a maximum of 10 characters. Determine the minimum buffer size in bytes, the byte filled by DOS for actual count, and the address offset of the first input character if the buffer starts at offset 0200h.

Example
Given:
Max characters allowed = 10 (set at buffer[0])
Buffer start address = 0200h

Why this formula applies:
Function 0Ah buffer layout:
  Byte 0: max chars (programmer defined)
  Byte 1: actual chars entered (DOS fills)
  Byte 2 onwards: actual input string + CR

Formula:
Minimum buffer size = max_chars + 2 bytes
First input character offset = buffer_start + 2

Substitution:
Minimum buffer size = 10 + 2 = 12 bytes
First char address = 0200h + 2 = 0202h
Actual count stored at: 0200h + 1 = 0201h

Calculation:
If user types 'HELLO' (5 chars) + Enter:
  Buffer[0201h] = 05h
  Buffer[0202h..0206h] = 'H','E','L','L','O'
  Buffer[0207h] = 0Dh (carriage return)

Final Answer:
Minimum buffer size = 12 bytes
First input character address = 0202h
Actual count byte address = 0201h
Exam Tip: For AH=09h, the string MUST end with '$' (24h), not a null byte. Forgetting the '$' terminator is the most common mistake. Also, AH=4Ch exit code in AL is often 00h for successful termination and is frequently asked in viva and practicals.
DOS Function 0Ah Buffer Layout and String Display MechanismAH=0Ah Buffer LayoutByte 0Max charsByte 1Actual countByte 2 onwardsInput chars + CRExample: Max=10User types HELLO + Enter0A | 05 | H | E | L | L | O | 0DByte[1]=05h (DOS filled)Last byte = 0Dh (carriage return)Buffer total size = max + 2 bytesAH=09h String DisplayMemory at DS:DX:'H','e','l','l','o',' ','W','o','r','l','d','$'DOS prints from DS:DX until '$'The '$' (24h) is NOT printedDX = offset of string in DSOutput: Hello WorldProgram Termination: AH=4ChMOV AH, 4ChMOV AL, 00h (exit code 0 = success)INT 21h
Figure 2: DOS function 0Ah buffer memory layout and function 09h string display mechanism
  • AH holds function number; INT 21h dispatches to the correct DOS handler.
  • AH=01h reads character with echo; AH=08h reads without echo; both return ASCII in AL.
  • AH=02h displays character in DL; AH=09h displays string at DS:DX terminated by '$'.
  • AH=0Ah buffer: byte 0 = max count, byte 1 = actual count (DOS fills), bytes 2+ = input.
  • AH=4Ch terminates program; AL = exit code (00h for normal exit).
  • Minimum buffer size for AH=0Ah = max_chars + 2 bytes.

Quick Revision

  • INT 21h is the gateway to all DOS services; AH = function selector.
  • AH=01h: char in (echo); AH=02h: char out (DL); AH=08h: char in (no echo).
  • AH=09h: string output from DS:DX, string must end with '$'.
  • AH=0Ah: buffered input; buffer size = max + 2; byte 1 = actual count filled by DOS.
  • AH=4Ch: terminate; AL = 00h for clean exit.
  • Exam trap: AH=09h will NOT stop at null (00h); it stops only at '$' (24h).
  • For multi-digit number display using AH=02h, binary-to-ASCII conversion loop is needed.

DOS Function Calls

Utilize INT 21h for system operations.

Question 1 of 3

Q1.Which AH register value is required for the INT 21h function to display a string?