Explain the concept of interrupts. Describe interrupt hardware and explain different types of interrupts.
Explain the concept of interrupts. Describe interrupt hardware and explain different types of interrupts.
Quick answer
An interrupt is a signal that makes the CPU stop its current program for a while, run a special routine called the interrupt service routine (ISR), and then go back to the program. It lets the CPU respond quickly to events such as a key press, a disk finishing, or an error, without wasting time in checking for them again and again.
Concept of an interrupt
When the CPU accepts an interrupt, it completes the current instruction. It saves the program counter and the flags on the stack. Then it loads the address of the ISR into the program counter. At the end, a return instruction restores the saved values.
Interrupt hardware
The hardware has the following parts.
- Interrupt request lines: each device has a line (INTR) to the CPU. Many devices can share one line by an OR connection.
- Interrupt flip-flop (mask): it enables or disables interrupts. The CPU can set it by the EI and DI instructions.
- Interrupt controller: a chip such as the Intel 8259 takes requests from many devices, decides the priority, and sends the vector number to the CPU.
- Interrupt acknowledge (INTA): the CPU sends this signal to tell the device that its request is accepted. The device then puts its vector on the data bus.
- Priority circuit: a daisy chain connects the devices in series, so the one nearest to the CPU has the highest priority. A parallel priority encoder can also be used.
Types of interrupts
Hardware interrupts come from outside the CPU. Maskable interrupts (INTR) can be disabled by the program. The non-maskable interrupt (NMI) cannot be disabled and is used for serious events such as a power failure.
Software interrupts are caused by an instruction in a program, such as INT n. They are used to call operating system services.
Exceptions (traps) are raised by the CPU itself when an instruction has a problem, for example a divide by zero, an overflow, an illegal opcode or a page fault.
Interrupts may also be vectored, where the device gives the address of the ISR, or non-vectored, where the CPU jumps to one fixed address and polls the devices to find the cause.
When several interrupts come together, the one with the highest priority is served first. The NMI and exceptions usually come before the ordinary device interrupts.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.
Up nextExplain the working of Direct Memory Access. Describe the DMA controller and its advantage