Download presentation
Presentation is loading. Please wait.
1
Microprocessor and Assembly Language
Interrupts
2
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)
3
Interrupt Vectors An interrupt vector is a 4-byte number stored in the first 1024 bytes of the memory (00000H–003FFH) 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
4
Interrupt Vectors The segment not present interrupt: occur when the segment is not present or not valid
5
The Operation of a Real Mode Interrupt
When an interrupt occur the processor do the following: 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. The contents of the code segment register (CS) are pushed onto the stack. The contents of the instruction pointer (IP) are pushed onto the stack. The interrupt vector contents are fetched, and then placed into both IP and CS jumps to the new location addressed by CS and IP/EIPThe 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.
6
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
7
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. INT 3 :A special software interrupt designed to function as a breakpoint.
8
INTs 256 different software interrupt instructions (INTs) available to the programmer. each INT instruction has a numeric operand whose range is 0 to 255 (00H–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 10H instruction calls the interrupt service procedure whose address is stored beginning at memory location 40H (10H 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
9
INTs Example Software interrupts will call interrupt service procedure either in BIOS or DOS INT 21h MS-DOS Services The general syntax for calling the functions is mov ah, function number ; input parameters int 21h ; return values • Output functions: – 02h, 06h - Write character to standard output – 05h - Write character to default printer – 09h - Write string to standard output – 40h - Write string to file or device • Input functions: – 01h, 06h - Read character from standard input – 0Ah - Read array of buffered characters from standard input – 0Bh - Get status of the standard input buffer – 3Fh - Read from file or device Ex.: Write the letter 'A' to standard output: mov ah,02h mov dl,’A’ int 21h
10
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
11
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.