Interrupts in the 8086 Microprocessor
Interrupts are a core feature of the Intel 8086 microprocessor that allows the processor to respond promptly to external or internal events. Interrupts temporarily suspend normal program execution, run a specific procedure (called an interrupt service routine (ISR)), and then resume execution of the original program. Below is a detailed description of interrupts in the 8086:
Types of Interrupts
The 8086 processor supports three types of interrupts:
Hardware Interrupts
They are triggered by external devices through the INTR (interrupt request) or NMI (non-maskable interrupt) pins.
INTR: maskable interrupt (it can be enabled/disabled with the IF (interrupt flag) in the flags register).
NMI: non-maskable interrupt (it cannot be disabled and has a higher priority than INTR).
Software Interrupts
They are triggered by executing the INT instruction in a program. They are used for system calls, debugging and calling BIOS/DOS procedures.
Internal Interrupts (Exceptions)
They are triggered by the processor itself because of errors or special conditions (for example, division by zero or overflow).
Interrupt Vector Table (IVT)
The 8086 processor uses the interrupt vector table (IVT) to manage interrupts. The IVT is a table of addresses (pointers) that point to the interrupt service routines (ISRs) for each interrupt type.
Location: the IVT is located at the beginning of memory (addresses 00000h to 003FFh).
Size: the IVT contains 256 entries of 4 bytes each (2 bytes for the CS register and 2 bytes for the IP register).
Format: each entry in the IVT corresponds to an interrupt number (from 0 to 255).
Calculating the interrupt vector: the interrupt number (n) is multiplied by 4 to obtain the ISR address in the IVT: ISR Address = n * 4. The 4 bytes at this address contain the new CS:IP values for the ISR.
Interrupt Process
When an interrupt occurs, the 8086 performs the following actions:
Saves the Current State: pushes the flags register, CS and IP onto the stack.
Disables Interrupts: clears IF (the interrupt flag) to disable further maskable interrupts.
Obtains the ISR Address: multiplies the interrupt number by 4 to find the ISR address in the IVT. Loads the new CS:IP values from the IVT.
Executes the ISR: jumps to the ISR and executes the interrupt handling code.
Restores the State: executes the IRET (return from interrupt) instruction to pop the saved IP, CS and flags register from the stack. Resumes normal program execution.
Interrupt Priorities
The 8086 processor assigns the following priorities to interrupts:
Internal Interrupts (Exceptions): highest priority.
NMI (non-maskable interrupt): medium priority.
INTR (maskable interrupt): lowest priority.
Interrupt Control Instructions
The 8086 processor provides several instructions for managing interrupts:
STI (set interrupt flag): enables maskable interrupts by setting IF.
CLI (clear interrupt flag): disables maskable interrupts by clearing IF.
INT n (software interrupt): generates a software interrupt with the specified number (n).
IRET (return from interrupt): returns from the ISR, restoring the saved IP, CS and flags register.
Interrupt Handling Example
Hardware Interrupt (INTR)
An external device activates the INTR input. The 8086 processor completes the current instruction, saves the state and fetches the ISR address from the IVT. The ISR handles the interrupt and executes the IRET instruction to return to the main program.
Software Interrupt (INT)
mov ah, 09h ; DOS function to display a string lea dx, msg ; Load the address of the message int 21h ; Call the DOS interrupt
Common Interrupts in the 8086
| Interrupt Number | Purpose |
|---|---|
| INT 00H | Divide by zero |
| INT 01H | Single-step debugging |
| INT 03H | Breakpoint interrupt |
| INT 04H | Overflow interrupt |
| INT 08H | System timer interrupt |
| INT 09H | Keyboard interrupt |
| INT 10H | BIOS video services |
| INT 21H | DOS function calls |
Conclusion
Interrupts in the 8086 microprocessor are a powerful mechanism for handling external and internal events. Using the interrupt vector table (IVT), the 8086 microprocessor can efficiently manage several interrupt sources and run the corresponding interrupt service routines (ISRs). Understanding interrupts is essential for writing efficient and responsive programs, especially in real-time systems and operating systems.