Chapter 5 · Simulation

Interrupt Vector Table: INT and IRET

← Chapter 5
Source code · offset
    Vector table (0000:0000–03FF)
    Stack (SS = 0700h)
    Screen

    Interrupt Vector Table: INT and IRET

    Goal: See, in order, what the 8086 does when an interrupt arrives. The first 1 KB of memory (00000h–003FFh) holds 4-byte vectors for the 256 interrupt types: the vector of type n is at address n × 4; the low word is IP and the high word is CS (both little-endian).

    Interrupt sequence

    1. FLAGS is pushed onto the stack (SP − 2).
    2. IF = 0 and TF = 0 are set.
    3. CS, then the return IP, are pushed onto the stack: 6 bytes in total.
    4. IP ← [n × 4], CS ← [n × 4 + 2]: the interrupt service routine (ISR) starts.
    5. The IRET at the end of the ISR restores IP, CS and FLAGS in the reverse of the order they were pushed. Because the old value of IF comes back with FLAGS, interrupts are enabled again.

    Scenarios

    • INT 10h: a software interrupt; the vector is F000:F065 (the video routine of the original IBM PC BIOS). The ROM routine's own instructions are not shown, only its effect and its IRET.
    • INT 90h: the program writes its own routine into the vector table. Even if the routine changes the flags, IRET restores them.
    • Timer (IRQ0): a hardware interrupt is accepted at an instruction boundary. While IF = 0 the request waits; after STI one more instruction is executed, then the interrupt is accepted. The 8259A supplies the type number (08h on the PC) during the INTA' cycle; at the end of the routine an EOI (end of interrupt) is written to port 20h.
    • Divide error (INT 0): an interrupt generated by the processor itself. On the 8086 the address pushed on the stack is that of the instruction after the DIV (the 80286 and later push the faulting instruction itself).

    In the table at the top right, blue bytes are the IP part and red bytes the CS part; "??" is a value not yet known (left by the BIOS). The small calculator on the left gives the vector address of any type. Because bits 12–15 of FLAGS always read as 1 on the 8086, values such as F202h are written to the stack.

    With Try it yourself on, you predict the vector address, the number of bytes written to the stack and the return address.

    The code is written in emu8086 syntax; register, flag and stack values were checked against the shared 8086 interpreter.

    Related slides: Chapter 5.1 · Interrupts (the vector table, INT and IRET, hardware interrupts).