Interrupt handling

Watch how priority and the interrupt queue decide whether the processor continues the program or calls the ISR.

Theory Beginner+ Architecture · Priority · ISR ~8 min
The idea

Check the queue first

An interrupt is a signal that asks the processor to pause the current process. Each interrupt is given a priority and placed in the interrupt queue.

The processor finishes the current cycle, then checks the interrupt queue for a higher priority. A program runs at priority 2, and the printer interrupt has priority 1. The keyboard interrupt has priority 3, and the key is A.

If the priority is higher than the program, the processor stores the registers on the stack and calls the ISR (interrupt service routine).

Which interrupt should the processor handle first if both are waiting: priority 1 or priority 3?

TipFE means the fetch–execute cycle, and FDE means the fetch–decode–execute cycle. Lower priority: the processor runs the next FDE cycle for the program. Higher priority: it stores the registers, calls the ISR, then retrieves them from the stack.
ExampleWho is who
roles.txtCast
Program    priority 2, running
Printer    source, priority 1
Keyboard   source, priority 3, key A
Queue      interrupt queue
Processor  checks each priority
Stack      stores the registers
ISR        interrupt service routine

The stack is where the processor stores the registers of the current process. The processor retrieves those registers after the ISR if no higher-priority interrupt is waiting.

Interactive

Run the simulation

Watch the printer and the keyboard, then the queue, the stack, and the ISR.

Step 0 / 0
interrupt.txtSequence
Sources · queue · processor · stack · ISRdemo
Ready
Press Step to begin.
Shortcuts: Space play/pause · → step · ← back · R reset
Try it yourself

Put the steps in order

Click steps from the pool to build the eight-step sequence. Click a chosen step to remove it.

Your order
Click to add
Ready
Place all eight steps in the mark-scheme order.
Remember

Three ideas

Priority, the queue, the stack, and the ISR.

Queue

Into the queue

An interrupt is given a priority and placed in the interrupt queue. The processor finishes the current FE cycle, then checks the queue for a higher priority.

Priority

Lower or higher

If the interrupt has lower priority, the processor runs the next FDE cycle for the program. If the priority is higher, the processor stores the current registers on the stack.

ISR

Handle, then continue

The processor checks the source, calls the appropriate ISR, and the ISR handles the interrupt. If another higher-priority interrupt is waiting, the processor repeats the check. Otherwise it retrieves the registers from the stack and continues the program.