2022 23 2e

Computer Organization and Architecture2022-2310 marksInterrupts

Define interrupt. Also discuss different types of interrupt.

Define interrupt. Also discuss different types of interrupt.

Quick answer

An interrupt is a signal sent to the CPU by hardware or software that asks the CPU to stop its current program temporarily and run a special routine, the interrupt service routine (ISR). After the ISR, the CPU returns to the interrupted program from the same place. The CPU saves the program counter and the flags before it jumps, and restores them afterwards.

Definition

Interrupts remove the need for the CPU to wait for slow devices. The CPU can do useful work and is called only when something needs attention.

The CPU checks for an interrupt at the end of each instruction cycle. If one is pending and interrupts are enabled, it runs the interrupt cycle.

Types of interrupts

Interrupts are grouped in several ways.

Hardware interrupts come from external devices through the interrupt pins of the CPU.

  • Maskable interrupts can be enabled or disabled by the program, using flags such as IF. Keyboard and disk interrupts are examples. The CPU ignores them when they are masked.
  • Non-maskable interrupts (NMI) cannot be disabled. They signal very serious events such as power failure or a memory parity error, and have the highest priority.

Software interrupts are caused by an instruction in the program, such as INT n in the 8086 or a system call. They are used by programs to ask the operating system for a service, for example to read a file.

Exceptions (internal interrupts or traps) are raised by the CPU itself when it finds an unusual condition during an instruction. Examples are divide by zero, overflow, an illegal opcode, a page fault and a protection violation. They are synchronous, meaning that they happen at a fixed point of the program.

Interrupts are also classified by the way the service routine is found.

  • Vectored interrupts: the device sends a vector number, so the CPU jumps to the correct routine directly. This is fast.
  • Non-vectored interrupts: the CPU jumps to one fixed address, and the routine has to poll the devices to find the cause. This is slower.

Priority

When many interrupts come together, priority decides the order. Hardware priority is made by a daisy chain or a priority encoder. Software priority is made by polling. The NMI and the exceptions usually rank above ordinary device interrupts.

Difference between external and internal interrupts

PointExternal (hardware)Internal (exception, software)
SourceI/O devices and timersCPU or program
TimingAsynchronous, at any timeSynchronous, at a known instruction
ExamplesKeyboard, NMI, timerDivide by zero, INT n, page fault

An interrupt is thus the means by which a computer responds quickly to events in the outside world and to errors in the program itself.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.

Up nextExplain about stack organization used in processors. What do you understand by register st