Interrupt Processing 

When the CPU is started, the BIOS and DOS ISRs are loaded into memory and they stay memory resident. In order to have flexibility in storing these ISRs in memory in any location, their addresses are stored in an interrupt descriptor table (IDT) or interrupt vector table (IVT).

In protected mode the IDT can be stored at any location and its address is stored at the 48-bit register IDTR. In this case, the address of an ISR requires 8 bytes. So, the size of the IDT is 2048 bytes.

However, in real mode the IDT is stored at base address 0. In this case, the address of an ISR requires 4 bytes only, 2 bytes for the IP offset and 2 bytes for the CS. Since each entry in the IVT requires 4 bytes, the interrupt type is multiplied by 4 to get the corresponding ISR pointer in the table.

For example, the ISR pointer for INT 0 is 0000h, the pointer for INT 1 is 0004h, the pointer for INT 2 is 0008h, and the pointer for INT 21h is 0084h. For INT 21h, the IP register will be loaded with the 16-bit from addresses [0085:0084] and the CS register will be loaded with the 16-bit from addresses [0087:0086]. The following figure illustrates the input vector table layout in memory for the real mode.

Fig. m25030.1 Interrupt vector table layout in memory (real mode).

When an interrupt occurs, the following action is taken by the CPU:
Push flags register onto the stack,
Clear interrupt and trap flags,
Push CS register onto the stack,
Push IP register onto the stack,
Load CS register with the 16-bit at memory address [interrupt-typex4+2],
Load IP register with the 16-bit at memory address [interrupt-typex4].

Just like procedures, ISRs should end with a return statement to send control back to the interrupted program. The interrupt return instruction, IRET, is used for this purpose. When the IRET instruction is executed, the CPU performs the following steps:
Pop the 16-bit from the top of the stack into the IP register,
Pop the 16-bit from the top of the stack into the CS register,
Pop the 16-bit from the top of the stack into the flags register.