Microprocessor and Assembly Language Interrupts Introduction An interrupt

Microprocessor and Assembly Language Interrupts

Introduction • An interrupt is a software or hardware initiated procedure that interrupts whatever program is currently executing • An interrupt is either a hardware-generated CALL (externally derived from a hardware signal) or a software -generated CALL (internally derived from the execution of an instruction or by some other internal event) • Either type interrupts the program by calling an interrupt service procedure (ISP) or interrupt handler. • Software interrupts are special types of CALL instructions • Three types of software interrupt instructions (INT, INTO, and INT 3)

Interrupt Vectors • An interrupt vector is a 4 -byte number stored in the first 1024 bytes of the memory (00000 H– 003 FFH) when the microprocessor operates in the real mode • In the protected mode, the vector table is replaced by an interrupt descriptor table that uses 8 -byte descriptors to describe each of the interrupts. • There are 256 different interrupt vectors, and each vector contains the address of an interrupt service procedure. • Each vector contains the address ( offset and segment) of the interrupt service procedure (Interrupt service routine ISR). • Interrupt Service Procedure: is the procedure that is executed when the Hardware/software requests an interrupt • The first two bytes of the vector contain the IP and the last two bytes contain the CS

Interrupt Vectors The segment not present interrupt: occur when the segment is not present or not valid

The Operation of a Real Mode Interrupt • When an interrupt occur the processor do the following: 1. 2. 3. Complete the current instruction The contents of the flag register are pushed onto the stack. Both the interrupt (IF) and trap (TF) flags are cleared. This disables the INTR pin and the trap or single-step feature. 4. The contents of the code segment register (CS) are pushed onto the stack. 5. The contents of the instruction pointer (IP) are pushed onto the stack. 6. The interrupt vector contents are fetched, and then placed into both IP and CS 7. jumps to the new location addressed by • The pushed flags are returned to the state prior to the interrupt when the IRET instruction is encountered at the end of the interrupt service procedure. CS and IP/EIP

The Operation of a Protected Mode Interrupt • In the protected mode, interrupts have exactly the same assignments as in the real mode, but • In place of interrupt vectors, protected mode uses a set of 256 interrupt descriptors that are stored in an interrupt descriptor table (IDT) • The interrupt descriptor table is 256 descriptors , with each descriptor containing eight bytes • The interrupt descriptor table is located at any memory location in the system – the interrupt descriptor table addressed by (IDTR) register • Each entry in the IDT contains the address of the interrupt service procedure in the form of a segment selector and a 32 -bit offset address

Interrupt Instructions • The microprocessor has three different interrupt instructions that are available to the programmer: – INT, INTO, and INT 3 • In the real mode, each of these instructions fetches a vector from the vector table, and then calls the procedure stored at the location addressed by the vector. • In the protected mode, each of these instructions fetches an interrupt descriptor from the interrupt descriptor table – The descriptor specifies the address of the interrupt service procedure. – The interrupt call is similar to a far CALL instruction because it places the return address (IP/EIP and CS) on the stack.

INTs • 256 different software interrupt instructions (INTs) available to the programmer. – each INT instruction has a numeric operand whose range is 0 to 255 (00 H–FFH) • For example, INT 100 uses interrupt vector 100. • Address of the interrupt vector is determined by multiplying the interrupt type number by 4. – INT 10 H instruction calls the interrupt service procedure whose address is stored beginning at memory location 40 H (10 H x 4) in the mode • In protected mode, the interrupt descriptor is located by multiplying the type number by 8 – because each descriptor is 8 bytes long

INTs Example • Software interrupts will call interrupt service procedure either in BIOS or DOS • INT 21 h MS-DOS Services – The general syntax for calling the functions is mov ah, function number ; input parameters int 21 h ; return values • Output functions: – 02 h, 06 h - Write character to standard output – 05 h - Write character to default printer – 09 h - Write string to standard output – 40 h - Write string to file or device • Input functions: Ex. : Write the letter 'A' to standard output: mov ah, 02 h mov dl, ’A’ int 21 h – 01 h, 06 h - Read character from standard input – 0 Ah - Read array of buffered characters from standard input – 0 Bh - Get status of the standard input buffer – 3 Fh - Read from file or device

INTO/IRET • INTO: Interrupt on overflow (INTO) is a conditional software interrupt that tests the overflow flag (O) – If O = 0, the INTO instruction performs no operation; if O = 1 and an INTO instruction executes, an interrupt occurs via vector type number 4 • IRET instruction will: – – (1) pop stack data back into the IP (2) pop stack data back into C (3) pop stack data back into the flag register The IRET instruction accomplishes the same tasks as the POPF, followed by a far RET instruction

Interrupt Control • Two instructions control the INTR pin. • The set interrupt flag instruction (STI) places 1 in the I flag bit – which enables the INTR pin • The clear interrupt flag instruction (CLI) places a 0 into the I flag bit – which disables the INTR pin • The STI instruction enables INTR and the CLI instruction disables INTR
- Slides: 11