written 8.4 years ago by |
Applications of interrupts:
- Applications of interrupts include the following: system timers, disk I/O, power-off signals, and traps.
- Other interrupts exist to transfer data bytes using UARTs or Ethernet; sense key-presses; or anything else the equipment must do.
- Another typical use is to generate periodic interrupts by dividing the output of a crystal oscillator and having an interrupt handler count the interrupts in order for a processor to keep time.
- These periodic interrupts are often used by the OS's task scheduler to reschedule the priorities of running processes.
- Some older computers generated periodic interrupts from the power line frequency because it was controlled by the utilities to eliminate long-term drift of electric clocks.
- For example, a disk interrupt signals the completion of a data transfer from or to the disk peripheral; a process waiting to read or write a file starts up again.
- As another example, a power-off interrupt predicts or requests a loss of power, allowing the computer equipment to perform an orderly shut-down.
- Also, interrupts are used in type ahead features for buffering events like keystrokes.
Interrupts:
- An interrupt is a special condition that arises during the working of a microprocessor. The microprocessor services it by executing a subroutine called Interrupt Service Routine (ISR).
- There are three sources of interrupts for 8086:
Hardware interrupt-
These interrupts occur as signals on the external pins of the microprocessor. 8086 has two pins to accept hardware interrupts, NMI and INTR.
Software interrupt-
These interrupts are caused by writing the software interrupt instruction INT n where ‘n’ can be any value from 0 to 255 (00H to FFH). Hence all 256 interrupts can be invoked by software.
Error conditions (Exception or types)-
8086 is interrupted when some special conditions occur while executing certain instructions in the program. Example: An error in division automatically causes the INT 0 interrupt.
Interrupt Vector Table (IVT):
- The interrupt vector (or interrupt pointer) table is the link between an interrupt type code and the procedure that has been designated to service interrupts associated with that code. 8086 supports total 256 types i.e. 00H to FFH.
- For each type it has to reserve four bytes i.e. double word. This double word pointer contains the address of the procedure that is to service interrupts of that type.
- The higher addressed word of the pointer contains the base address of the segment containing the procedure. This base address of the segment is normally referred as NEW CS.
- The lower addressed word contains the procedure’s offset from the beginning of the segment. This offset is normally referred as NEW IP.
- Thus NEW CS: NEW IP provides NEW physical address from where user ISR routine will start.
- As for each type, four bytes (2 for NEW CS and 2 for NEW IP) are required; therefore interrupt pointer table occupies up to the first 1k bytes (i.e. 256 x 4 = 1024 bytes) of low memory.
The total interrupt vector table is divided into three groups namely,
A. Dedicated interrupts (INT 0…..INT 4)
B. Reserved interrupts (INT 5…..INT 31)
C. Available interrupts (INT 32…..INT 225)
A. Dedicated interrupts (INT 0…..INT 4):
INT 0 (Divide Error)-
- This interrupt occurs whenever there is division error i.e. when the result of a division is too large to be stored. This condition normally occurs when the divisor is very small as compared to the dividend or the divisor is zero.
- Its ISR address is stored at location 0 x 4 = 00000H in the IVT.
INT 1 (Single Step)-
- The microprocessor executes this interrupt after every instruction if the TF is set.
- It puts microprocessor in single stepping mode i.e. the microprocessor pauses after executing every instruction. This is very useful during debugging.
- Its ISR generally displays contents of all registers. Its ISR address is stored at location 1 x 4 = 00004H in the IVT.
INT 2 (Non mask-able Interrupt)-
- The microprocessor executes this ISR in response to an interrupt on the NMI (Non mask-able Interrupt) line.
- Its ISR address is stored at location 2 x 4 = 00008H in the IVT.
INT 3 (Breakpoint Interrupt)-
- This interrupt is used to cause breakpoints in the program. It is caused by writing the instruction INT 03H or simply INT.
- It is useful in debugging large programs where single stepping is efficient.
- Its ISR is used to display the contents of all registers on the screen. Its ISR address is stored at location 3 x 4 = 0000CH in the IVT.
INT 4 (Overflow Interrupt)-
- This interrupt occurs if the overflow flag is set and the microprocessor executes the INTO (Interrupt on Overflow) instruction.
- It is used to detect overflow error in signed arithmetic operations.
- Its ISR address is stored at location 4 x 4 = 00010H in the IVT.
B. Reserved interrupts (INT 5…..INT 31):
- These levels are reserved by Intel to be used in higher processors like 80386, Pentium etc. They are not available to the user.
C. Available interrupts (INT 32…..INT 225):
- These are user defined, software interrupts.
- ISRs for these interrupts are written by the users to service various user defined conditions.
- These interrupts are invoked by writing the instruction INT n. Its ISR address is obtained by the microprocessor from location n x 4 in the IVT.
Hardware Interrupts:
NMI (Non mask-able interrupt)-
- This is a non-mask-able, edge triggered, high priority interrupt.
- On receiving an interrupt on NMI line, the microprocessor executes INT
- Microprocessor obtains the ISR address from location 2 x 4 = 00008H from the IVT.
- It reads 4 locations starting from this address to get the values for IP and CS to execute the ISR.
INTR-
- This is a mask-able, level triggered, low priority interrupt.
- On receiving an interrupt on INTR line, the microprocessor executes 2 $\overline{INTA}$ pulses.
1st $\overline{INTA}$ pulse – The interrupting device calculates (prepares to send) the vector number.
2nd $\overline{INTA}$ pulse – The interrupting device sends the vector number ‘N’ to the microprocessor.
- Now microprocessor multiplies N x 4 and goes to the corresponding location in the IVT to obtain the ISR address. INTR is a mask-able interrupt.
- It is masked by making IF = 0 by software through CLI instruction.
- It is unmasked by making IF = 1 by software through STI instruction.