Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

8086 interrupts and the interrupt vector table

Clear, exam-focused notes on 8086 interrupts and the Interrupt Vector Table (IVT): what interrupts are, how the 8086 uses the IVT to find ISRs, stack effects, vector layout and worked examples.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Interrupts let the CPU stop its normal instruction stream to respond to external events (I/O devices, timers) or internal exceptions (divide by zero). An engineer uses interrupt and IVT knowledge when writing low-level OS code, device drivers, BIOS code, or when debugging boot problems — you must know how the 8086 finds and calls an ISR and how to restore state with IRET.

Key ideas

  • Vector number: an 8-bit number (0–255) that identifies which ISR to call. It indexes into the Interrupt Vector Table (IVT).

  • Interrupt Vector Table (IVT): a table of 256 vectors at physical address 00000h (segment:offset 0000:0000). Each vector is 4 bytes (a 16-bit offset followed by a 16-bit segment) that together give the CS:IP of the ISR. Therefore the IVT occupies the first 1024 bytes (1 KB) of physical memory.

    Exact statement: IVT base address = 0000:0000. Entry for vector n begins at byte offset 4·n from the base. The word at that offset (first two bytes, little-endian) is the offset (IP) and the next word is the segment (CS).

  • Software interrupt (INT n): an instruction that causes a synchronous, software-generated interrupt. The immediate byte n is the vector number. INT 3 is a special one-byte breakpoint instruction. Predefined CPU exception vectors on 8086: 0=Divide Error, 1=Single-step (Trap Flag), 2=NMI, 3=Breakpoint, 4=Overflow (INTO).

  • Hardware interrupts: 8086 has at least two dedicated inputs: INTR (maskable) and NMI (non-maskable). When a maskable interrupt arrives, it is recognized only if the IF (Interrupt Flag) in FLAGS is 1. NMI is always recognized (it is not blocked by IF).

  • Interrupt entry sequence (what 8086 does when it accepts an interrupt): (1) complete the current instruction; (2) push FLAGS on the stack; (3) push CS on the stack; (4) push IP on the stack; (5) clear TF and IF; (6) load new CS:IP from the IVT entry for the vector. (All pushes are 16-bit words; stack grows downward.)

    Exact statement for software INT n: CPU pushes FLAGS, CS, IP (in that order), clears IF and TF, then loads CS:IP from IVT[n]. For IRET: pop IP, pop CS, pop FLAGS (restoring IF/TF as they were).

  • Data representation and byte order: 8086 stores multi-byte values in little-endian: low-order byte first. Therefore each IVT entry contains offset low byte, offset high byte, segment low byte, segment high byte.

  • Size and addressing: Number of vectors = 256. Size per vector = 4 bytes. IVT size = 256·4 = 1024 bytes. Address of vector n (byte) = 4·n. In segmented addressing terms, the IVT is at segment 0000h, offset 0000h.

  • Return from interrupt: IRET pops IP, CS, FLAGS (in that order). After IRET the processor resumes execution where it left off with FLAGS restored.

  • Vectored vs. non-vectored hardware interrupts: On a vectored interrupt the device (or the PIC) supplies a vector number; on non-vectored, the CPU may have a fixed or implied handler. In PC-compatible systems an 8259 PIC provides vectored service by supplying the vector to the CPU during the interrupt acknowledge cycle. On 8086 specifically, NMI uses fixed vector 2 (type 2), and INTR obtains an 8-bit vector during the interrupt acknowledge cycle (from the device or the 8259 PIC).

  • Diagram(s) to draw for an exam answer: (1) Memory map: draw address axis from 00000h showing the first 1 KB labelled IVT; mark vector 0 at 00000h and vector 255 starting at 003FCh (last byte at 003FFh). (2) IVT entry layout: draw 4 bytes horizontally and label bytes 0..3 with "offset low", "offset high", "segment low", "segment high". (3) Interrupt entry flow: box with steps: finish instruction -> push FLAGS -> push CS -> push IP -> clear IF/TF -> fetch CS:IP from IVT -> jump.

Formulas

IVT_base = 0000h:0000h (physical 00000h) — IVT start address.

entry_byte_address = 4 * n — byte offset within IVT for vector n (n = 0..255).

IVT_size = 256 * 4 = 1024 bytes — total bytes of IVT.

push sequence on interrupt: SP := SP - 2; [SS:SP] := FLAGS; SP := SP - 2; [SS:SP] := CS; SP := SP - 2; [SS:SP] := IP — shows stack effect (words).

IRET sequence: IP := [SS:SP]; SP := SP + 2; CS := [SS:SP]; SP := SP + 2; FLAGS := [SS:SP]; SP := SP + 2 — order of pop on return.

vector_physical_address = 4*n — physical byte address from absolute 0, to look up CS:IP.

Syntax to remember: INT imm8 (software interrupt), IRET (return from interrupt), INT3 (breakpoint, opcode 0xCC), INTO (interrupt on overflow — vector 4 if OF=1; otherwise no interrupt).

Worked examples

  1. Find the IVT entry address and ISR pointer for vector 0x21 (33 decimal). Suppose memory at physical addresses 00084h..00087h contains bytes: 34 12 00 F0 (shown low-to-high addresses).

    Steps:

    1. Compute entry byte address: 4 * 0x21 = 0x84 (byte offset 0x84 = physical address 00084h).
    2. Read first word (offset) in little-endian: low byte = 34h, high byte = 12h -> offset = 0x1234.
    3. Read next word (segment) little-endian: low byte = 00h, high byte = F0h -> segment = 0xF000.
    4. ISR address = CS:IP = F000:1234. Physical address = F000h*16 + 1234h = F0000h + 1234h = F1234h (within the 20-bit physical address space, so no wrap/truncation occurs on 8086). Bold result: ISR = F000:1234.
  2. Show stack contents after a software INT 21h when SS = 2000h, SP initially = FFFEh, CS = 3000h, IP = 0100h, FLAGS = 0202h. Assume CPU accepts the interrupt.

    Steps:

    1. Initial SP = FFFE.
    2. Push FLAGS: SP := FFFE - 2 = FFFCh; [2000:FFFC] := 0202h (store low byte 02h then 02h).
    3. Push CS: SP := FFFC - 2 = FFFAh; [2000:FFFA] := 3000h.
    4. Push IP: SP := FFFA - 2 = FFF8h; [2000:FFF8] := 0100h.
    5. After pushes, SP = FFF8h. The CPU then clears IF/TF and loads CS:IP from IVT[21h]. Bold final stack top: SP = FFF8h, memory at SS:FFF8..FFFF holds IP, CS, FLAGS (in that order from lowest address upward).

    (Show bytes if exam asks: list addresses and contents in little-endian order.)

  3. Model-answer style long question: "Describe precisely what happens inside the 8086 when a hardware device requests an interrupt through INTR and the CPU accepts it. Draw the IVT entry layout and show the stack contents after entry." — A full-marks answer should mention: instruction completion, push FLAGS, CS, IP (words), clear TF/IF, compute IVT byte address = 4·vector, fetch 16-bit offset then 16-bit segment (little-endian) and load CS:IP, and that IVT resides at physical 00000h..003FFh (1 KB). Draw the IVT entry as 4 bytes: offset low, offset high, segment low, segment high. Show stack addresses and values as in example 2.

Common mistakes

  • Forgetting little-endian ordering inside a vector entry (offset first, then segment, each as little-endian words).
  • Thinking the IVT is in BIOS ROM only: BIOS and OS can modify IVT entries; by default reset vectors may point into ROM, but IVT is at physical address 0x00000 in RAM/ROM depending on system design.
  • Believing NMI is maskable by IF — it is not.
  • Mixing up software INT vector supply (immediate operand) and hardware vectored interrupts (device or PIC supplies vector during interrupt acknowledge) — be clear which case you mean.

For your exam

Types of questions:

  • Definitions: explain IVT, vector, ISR, maskable/unmaskable.
  • Short notes: layout of IVT, interrupt entry/exit sequence, difference between INT and NMI.
  • Derivations/diagrams: draw IVT layout and show calculation of IVT address for a given vector n; draw stack content after an interrupt.
  • Numericals: given memory bytes at a vector entry, compute CS:IP and physical address of ISR; given initial SP/SS, compute stack after interrupt.
  • Programs: simple assembly snippet using INT and handling IRET (but full OS-level context switching is out of scope).

What a full-marks answer includes:

  • Exact IVT location and size (0000:0000, 1 KB), formula for entry address (4·n).
  • Correct byte order and statement that each entry contains IP then CS (each 16 bits, little-endian).
  • Exact push/pop order and the fact that IF/TF are cleared on entry and restored by IRET.
  • Clear diagrams or memory maps when asked.

Quick check

  1. Where in memory is the IVT located?
  2. How many bytes per vector entry and how many vectors are there?
  3. What register pair is loaded from IVT entry to transfer control to the ISR?

Answers: 1) At segment:offset 0000:0000 (physical 00000h). 2) 4 bytes per entry, 256 vectors (total 1024 bytes). 3) CS:IP (CS loaded from the segment word, IP/offset loaded from the offset word).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?