In 8086 assembly programming, interrupts play a crucial role in handling various operations, from debugging to system calls. Two commonly used interrupts are INT 3h
(Breakpoint Interrupt) and INT 21h
(DOS Interrupt). While both involve interrupt handling, their functionalities and use cases are completely different.
In this blog post, we will explore the differences between INT 3h
and INT 21h
, their respective use cases, and practical examples to understand their behavior.
TL;DR
INT 3h
is used for debugging; it stops execution and hands control to the debugger.INT 21h
is used for system services like displaying messages, reading input, and terminating the program.- Key Difference:
INT 3h
is a 1-byte instruction (CC
), whileINT 21h
requires function numbers inAH
to specify system calls.
What is INT 3h
?
INT 3h
is a breakpoint interrupt primarily used for debugging assembly programs. When executed, it stops the program and allows a debugger to inspect the registers and memory. This interrupt is commonly inserted in programs to mark breakpoints during development.
Key Features of INT 3h
- Used for debugging purposes.
- Causes the program to halt and transfers control to a debugger.
- Uses a 1-byte opcode (
CC
), making it an efficient way to set breakpoints.
What is INT 21h
?
INT 21h
is a DOS interrupt that provides access to MS-DOS system services. It allows assembly programs to perform system-level operations such as displaying text, reading user input, handling files, and terminating programs.
Key Features of INT 21h
- Used for system functions in MS-DOS.
- Requires a function number in the
AH
register to specify the operation. - Commonly used for input/output operations, program termination, and file management.
Difference Between INT 3h
and INT 21h
The following table summarizes the key differences between INT 3h
and INT 21h
:
Feature | INT 3h (Breakpoint Interrupt) | INT 21h (DOS Interrupt) |
---|---|---|
Purpose | Debugging and breakpoint setting | Accessing DOS system services |
Function | Halts execution and invokes the debugger | Performs system-level operations |
Opcode | CC (1-byte instruction) | CD 21 (2-byte instruction) |
Common Uses | Debugging, inspecting memory and registers | Displaying text, reading input, program termination |
Requires Additional Parameters? | No | Yes (Function number in AH ) |
Example 1: Using INT 3h
for Debugging
.model small .stack 100h .data msg db 'Debugging with INT 3h', 0Dh, 0Ah, '$' .code main proc mov ax, @data ; Load data segment mov ds, ax mov dx, offset msg mov ah, 09h ; DOS function to print string int 21h ; Call DOS interrupt to display message int 3 ; Trigger breakpoint interrupt mov ah, 4Ch ; DOS function to terminate program int 21h ; Call DOS interrupt main endp end main
Expected Output:
Debugging with INT 3h
When run under a debugger, execution will halt at INT 3h
, allowing the user to inspect registers and memory.
Example 2: Using INT 21h
for System Calls
.model small .stack 100h .data msg db 'Hello, World!', 0Dh, 0Ah, '$' .code main proc mov ax, @data ; Load data segment mov ds, ax mov dx, offset msg mov ah, 09h ; DOS function to print string int 21h ; Call DOS interrupt to display message mov ah, 4Ch ; DOS function to terminate program int 21h ; Call DOS interrupt main endp end main
Expected Output:
Hello, World!
The program uses INT 21h
to display a string and terminate the program.
Understanding these interrupts is essential for efficient debugging and DOS system programming in 8086 assembly. Mastering their differences will help you write better assembly programs with improved debugging and system interaction capabilities.
Do you have any questions? Let me know in the comments! 😊