Why computers use interrupts

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Why computers use interrupts

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Why do computers use interrupts instead of the CPU constantly checking every device?
A The CPU only responds when a device needs attention, so it is free to run programs
B The CPU must check every device after every instruction to stay safe
2. Which statement describes what happens WITHOUT interrupts (constant checking, called polling)?
A The CPU wastes time repeatedly checking whether a device needs attention
B The CPU is told straight away when a device needs attention
3. A user presses a key while a program is running. Why is an interrupt useful here?
A The CPU has to stop the program and keep checking the keyboard until a key is pressed
B The keyboard signals the CPU, which gives a quick response to the key press
4. Which is a benefit of using interrupts?
A Urgent events have to wait until the CPU's next scheduled check
B Urgent events get a quick response from the CPU
5. True or false: an interrupt is a signal that tells the CPU an event needs attention.
A True
B False

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1while no_key_pressed: check_keyboard() APolling: the CPU keeps checking the keyboard again and again, wasting time that could be used to run programs
2CPU runs program; key pressed -> interrupt signal sent BIF interrupt_received THEN handle_event()
3Interrupts free the CPU to run programs, because it does not have to keep checking each device CThis is wrong because with interrupts the printer signals the CPU when it needs attention, so the CPU is not stuck checking and can run other programs.
4Interrupts give a quick response to an urgent event, such as a device needing attention immediately DAn interrupt: the CPU keeps running programs and only responds when the keyboard signals that it needs attention
5Interrupts make the CPU check the mouse every millisecond to see if it moved EThis describes polling, not interrupts. With interrupts the mouse sends a signal only when it moves, so the CPU does not keep checking.
6A printer has to wait until the CPU happens to check it, so the CPU is always busy with it FRUN program_A // no checking of devices needed

Definitions

interrupt

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
_____ TRUE CHECK keyboard ENDWHILE
2.
// An _________ alerts the CPU to an event
3.
// Constant checking of devices = _______
4.
// Interrupts give a _____ response
5.
// The CPU is ____ to run other programs

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A EVERY cycle check the keyboard
B Keyboard sends interrupt
C CPU runs the keyboard ISR
Question 2
A CPU runs a spreadsheet
B Printer is out of paper
C Printer waits to be polled
Question 3
A Polling saves CPU time
B Interrupts only act on events
C So CPU can run other programs
Question 4
A CPU is running a video editor
B Battery level becomes critical
C An interrupt waits its turn
Question 5
A No interrupt has happened
B CPU must wait for the device
C Interrupt signal arrives
D CPU then deals with the event

Answer Key

Why computers use interrupts
Section A: Quick Questions
Q1
A — The CPU only responds when a device needs attention, so it is free to run programs
Q2
A — The CPU wastes time repeatedly checking whether a device needs attention
Q3
B — The keyboard signals the CPU, which gives a quick response to the key press
Q4
B — Urgent events get a quick response from the CPU
Q5
A — True
Section B: Match the Pairs
Q1
while no_key_pressed: check_keyboard() → Polling: the CPU keeps checking the keyboard again and again, wasting time that could be used to run programs
Q2
CPU runs program; key pressed -> interrupt signal sent → An interrupt: the CPU keeps running programs and only responds when the keyboard signals that it needs attention
Q3
Interrupts free the CPU to run programs, because it does not have to keep checking each device → RUN program_A // no checking of devices needed
Q4
Interrupts give a quick response to an urgent event, such as a device needing attention immediately → IF interrupt_received THEN handle_event()
Q5
Interrupts make the CPU check the mouse every millisecond to see if it moved → This describes polling, not interrupts. With interrupts the mouse sends a signal only when it moves, so the CPU does not keep checking.
Q6
A printer has to wait until the CPU happens to check it, so the CPU is always busy with it → This is wrong because with interrupts the printer signals the CPU when it needs attention, so the CPU is not stuck checking and can run other programs.
Section C: Definitions
Q1
interrupt — A signal that tells the CPU an event needs attention, so it responds only when needed instead of constantly checking devices (polling). This frees the CPU and gives a quick response.
Section D: Fill in the Blanks
Q1
WHILE TRUE CHECK keyboard ENDWHILE
Q2
// An interrupt alerts the CPU to an event
Q3
// Constant checking of devices = polling
Q4
// Interrupts give a quick response
Q5
// The CPU is free to run other programs
Section E: Spot the Error
Q1
A — Interrupts mean the CPU reacts only WHEN the key is pressed. Checking the keyboard every cycle is polling, which wastes CPU time. Line 1 should be WHEN key is pressed.
Q2
C — With interrupts the device sends a signal to the CPU when it needs attention. It does not wait to be polled. Line 3 should be Printer sends an interrupt.
Q3
A — Polling repeatedly checks devices, so it wastes CPU time. Interrupts avoid this. Line 1 should say polling wastes CPU time.
Q4
C — A key benefit of interrupts is a quick response to urgent events. The CPU does not leave them waiting. Line 3 should say an interrupt gets a quick response.
Q5
B — Until an interrupt arrives the CPU is free to run programs. It does not have to wait for the device. Line 2 should say the CPU is free to run programs.