Inter Ruts
Inter Ruts
Interrupts are signals that temporarily pause the normal execution of a program to allow the
CPU to deal with urgent tasks or events. Once the interrupt is serviced, the CPU resumes the
original program.
Sources of Interrupts
• The Interrupt Vector Table is a special memory area in the first 1 KB of memory
(from address 0000:0000 to 0000:03FFh).
• It contains pointers to interrupt service routines (ISRs) for all possible interrupts.
Structure of IVT
• The IVT has 256 entries (0 to 255) for 256 interrupt vectors.
• Each entry = 4 bytes:
o 2 bytes for IP (Instruction Pointer)
o 2 bytes for CS (Code Segment)
• So, total size = 256 vectors × 4 bytes = 1024 bytes = 1 KB
Memory Layout
Address = n × 4
Example Breakdown
• IV #2 = 2 × 4 = address 0008
• The ISR address is built from:
o IP = contents at 0008 (low) and 0009 (high)
o CS = contents at 000A (low) and 000B (high)
This ensures that when the ISR (Interrupt Service Routine) is done, the CPU can return to the
interrupted program exactly where it left off.
Now, the microprocessor fetches the address of the ISR from the Interrupt Vector Table
(IVT):
These pushes/pops are not automatic—you must add them in your ISR if you use registers.
What
Step Description
Happens
IRET
Pops IP, CS, and FLAGS from stack, returning execution to where it was
11
interrupted
Summary Flow
MAIN PROGRAM
↓
INTERRUPT OCCURS
↓
[Auto] PUSH FLAGS
[Auto] Clear IF, TF
[Auto] PUSH CS
[Auto] PUSH IP
[Auto] Get new CS:IP from IVT
↓
INTERRUPT SERVICE ROUTINE
[Optional] PUSH Registers
ISR CODE
[Optional] POP Registers
IRET
↓
MAIN PROGRAM CONTINUES
Examples:
Example:
MOV CL, 0
DIV CL ; INT 0 (Divide by Zero)
Step Action
1 A 0→1 edge occurs on the NMI pin.
2 The microprocessor completes the current instruction.
3 The CPU then responds by pushing FLAGS, CS, and IP onto the stack.
4 The CPU clears the IF and TF flags.
It fetches the Interrupt Vector #2 from the Interrupt Vector Table (at memory
5
00008h–0000Bh).
6 CPU performs a far jump to the ISR (Interrupt Service Routine) using the new CS:IP.
7 The ISR executes, then finishes with an IRET instruction.
Step Action
8 Execution returns to the interrupted program.
Feature Detail
Interrupt Vector Fixed at #2 (address 00008h–0000Bh)
Maskable ❌ No – cannot be disabled
Trigger Type Edge-triggered (positive edge)
Use Case Critical errors like power failure, parity errors
Priority Second only to internal (exception) interrupts
Recognition Delay Must remain LOW for 2 cycles before edge
Example Scenario
Let’s say a power failure detection circuit is connected to the NMI pin. When power drops
below a safe level:
Would you like help writing an example ISR for NMI in Assembly, or how to connect and test
NMI on a real system like with a timer or custom hardware circuit?
The BOUND instruction checks whether the value in a register lies within a lower and upper
bound stored in memory.
If the value is out of bounds, it triggers a software interrupt: INT 5.
Syntax:
BOUND reg16, mem
Operation:
IF (reg16 < [mem]) OR (reg16 > [mem+2])
THEN Interrupt 5 occurs (OUT OF BOUND)
ELSE
No interrupt (IN BOUND)
Given:
Now compare:
AX = 4050h
Suppose:
AX = 7080h
Then:
Notes on INT 5
• INT 5 is a software interrupt typically used for print-screen on original IBM PC (default
behavior), but here it's repurposed by BOUND instruction to signal a bounds check
failure.
• It can be handled by writing an ISR (Interrupt Service Routine) at vector 5 →
memory location 00014h–00017h (4 bytes: IP + CS).
This confirms:
Purpose:
Triggers an interrupt only if the Overflow Flag (OF) = 1.
Instruction:
INTO
Behavior:
IF OF == 1 THEN
Trigger INT 4 ; i.e., call interrupt vector #4
ELSE
Continue normal execution
Use Case:
To handle overflow conditions after signed arithmetic operations, e.g., after ADD, SUB.
Purpose:
Triggers interrupt vector #n, where n = 0 to 255.
Instruction:
INT n ; e.g., INT 21h for DOS calls, INT 10h for video
Step Action
1 PUSHF – Push FLAGS register
Step Action
2 Clear IF and TF flags (disable interrupts and trap)
3 PUSH CS – Push Code Segment
4 PUSH IP – Push Instruction Pointer
5 Load IP from memory (4 * n)
6 Load CS from memory (4 * n + 2)
7 Jump to ISR (Interrupt Service Routine)
Instruction:
Use Case:
Used by debuggers to insert a software breakpoint into the program.
Step Action
1 POP IP
2 POP CS
3 POPF
This restores the state saved when the interrupt occurred and resumes program execution.
Quick Summary
Instruction Description Causes INT #
INTO Triggers interrupt if OF == 1 INT 4
INT n Triggers user-defined or system INT INT n
INT 3 One-byte software breakpoint INT 3
IRET Returns from an interrupt —
• Keyboards
• Timers
• Peripheral controllers
• I/O devices
Key Characteristics:
Feature Details
Pin Used INTR (Interrupt Request)
Type Level-sensitive (must remain at logic 1 until acknowledged)
Maskable? ✅ Yes. Can be disabled by clearing the IF (Interrupt Flag)
Acknowledged by INTA (Interrupt Acknowledge) pulse from the CPU
Vector Source External device places interrupt vector type number on D7–D0
Returns using IRET (Interrupt Return Instruction)
Example
• Setting INTR = 1
• During INTA cycle, provides interrupt type = 35
Then:
(Recall: 4 × 35 = 008C)
Summary Table
Why Masking?
• To avoid interrupt storms or infinite nested interrupts of the same or lower priority.
• Ensures that only higher priority interrupts preempt the current service routine.
• The 8088/8086 microprocessor has only one INTR input pin for hardware interrupts
from I/O devices.
• Without expansion, only one device can be directly connected to this INTR line.
• To connect multiple interrupt sources, we need techniques to expand or multiplex the
interrupt signals.
Methods to Expand Interrupt Inputs:
1⃣ Using 74ALS244 Buffer
Summary Table:
Method Description Priority Handling Scalability
74ALS244 Simple buffering of interrupt
None (no arbitration) Limited
Buffer lines
Daisy-Chain Serial connection of devices Priority by position Moderate
Method Description Priority Handling Scalability
Programmable Interrupt Yes (software High
8259 PIC
Controller configurable) (cascadable)
Solution:
• Use 74ALS244 octal buffer/line driver IC to combine multiple interrupt lines from
different devices into the single INTR pin of the microprocessor.
How it Works:
Important Notes:
Outputs of 74ALS244 (all 8 outputs) are wired together ---> INTR pin of 8086
Summary:
Feature Explanation
IC Used 74ALS244 Octal buffer/line driver
Number of Interrupt
Up to 8 (one per input pin)
Inputs
Priority Handling None (all inputs combined with wired-OR)
Interrupt Signal to CPU Single INTR pin, high if any device asserts interrupt
Use Case Simple expansion for multiple interrupt lines
Feature Explanation
Does not resolve which device caused interrupt; no priority
Limitation
mechanism
The daisy-chain method connects the INTR (Interrupt Request) lines of multiple devices in a
chain, all leading to a single interrupt input pin on the microprocessor.
• Instead of assigning a separate interrupt line to each device, one interrupt line (INTR) is
shared.
• Devices signal interrupts in sequence, and software checks (polls) each device to find
who raised the interrupt.
Trade-off:
• Requires software polling, so interrupt handling takes more time than fixed priority
hardware like 8259A.
• If any one of the INTRs becomes 1, the combined signal to CPU's INTR pin goes high.
• CPU then executes ISR (Interrupt Service Routine).
• Inside ISR, the CPU polls each 8255 and each INTR line to find the source of the
interrupt.
This is software-based priority, and it can be written to suit your application’s needs.
Summary
• Daisy-chaining is a method to expand interrupt capability using minimal lines.
• 8255 in Mode 1 supports interrupts via Port C bits (INTE).
• You control interrupts via Command Byte B by setting bits in Port C.
• All INTRs go to a single CPU line, and the ISR uses polling to find the interrupt source.
We can set or reset individual bits of Port C using a special control word called
Command Byte B (also known as Bit Set/Reset (BSR) Mode).
Set bit 4 →
Set bit 2️ →
Set bit 6 →
• BBB = 110
• S=1
So again:
Summary Table
Purpose Bit to Set Bit No. (BBB) Command Byte (Bin) Hex
INTE A (Input) – PC4 PC4 100 00001001 09h
INTE B (Input) – PC2 PC2 010 00000101 05h
INTE A (Output) – PC6 PC6 110 00001101 0Dh
INTE B (Output) – PC2 PC2 010 00000101 05h
1. ICW1
o Defines the base interrupt vector number (e.g., IR0 = 08h, IR1 = 09h,
etc.)
o Example: OUT 21h, AL (AL = 08h → INT 08h for IR0)
3. ICW3 (Only in Cascade Mode)
1. OCW1
Key Differences
ICWs OCWs
Example: OUT 20h, 11h (ICW1) Example: OUT 20h, 20h (OCW2 EOI)
When to Use
This ensures the PIC knows how to handle interrupts (ICWs) and how to manage
them dynamically (OCWs).
ICW1
ICW2
This sets the base address (T7–T3) of the Interrupt Vector Table (used by 8088/8086). Each
interrupt adds 1 to the base.
• For Master:
o Bits D0–D7: Each bit represents whether a slave is connected to IR0–IR7
o Example: 00100000 = slave connected to IR5
• For Slave:
o Bits D0–D2: Give the ID of which IR line the slave is connected to on the master
o Example: 101 = connected to IR5
ICW4
Master
• µPM = 1 (8088)
• AEOI = 1
• BUF = 1 (Buffered)
• M/S = 1 (This is Master)
• SFNM = 1
Slave
• Cascade mode
• ICW4 needed
• LTIM = 1 → Level-triggered
• µPM = 1 (8088)
• AEOI = 0 (Normal EOI)
• BUF = 1, M/S = 0 (Slave)
• SFNM = 1