Hardware interrupts

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

Hardware interrupts

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A student presses a key on the keyboard while the CPU is running a program. What type of interrupt is generated?
A A hardware interrupt, sent by the keyboard
B A software interrupt, sent by the program
2. Which statement describes a hardware interrupt?
A A signal from a program telling the CPU it has made an error
B A signal from a hardware device telling the CPU it needs attention
3. A printer runs out of paper in the middle of a print job. What happens?
A The printer sends a hardware interrupt to the CPU
B The printer waits silently until the CPU checks it
4. Which event is an example of a hardware interrupt?
A Moving the mouse
B Dividing a number by zero in a program
5. Which device could generate a hardware interrupt?
A A variable that has been given a new value
B A device that has finished transferring data

Match the Pairs

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

Left columnRight column
1keyboard -> interrupt signal -> CPU Amouse moved -> hardware interrupt -> CPU
2printer: out of paper -> interrupt BPressing a key on the keyboard sends a hardware interrupt to the CPU so the key press can be dealt with.
3Moving the mouse is an event that makes the mouse send a hardware interrupt to the CPU. CA hardware interrupt is generated by the hardware device (the keyboard), not by the CPU. The CPU receives the signal and responds to it.
4A device that finishes a data transfer sends a hardware interrupt so the CPU knows it can carry on. Dtransfer complete -> hardware interrupt
5The CPU generates the hardware interrupt when a key is pressed. EA printer running out of paper generates a hardware interrupt to tell the CPU it needs attention.
6A hardware interrupt is caused by an error in a program, such as dividing by zero. FAn error in a program, such as divide by zero, causes a software interrupt. A hardware interrupt comes from a hardware device such as a keyboard, mouse or printer.

Definitions

hardware interrupt

Fill in the Blanks

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

1.
A ________ interrupt is sent by a device
2.
IF keyPressed THEN SEND _________ TO CPU
3.
IF paperTray _ 0 THEN SEND interrupt
4.
IF transferDone = TRUE ____ SEND interrupt
5.
IF mouseMoved THEN SEND interrupt TO ___

Spot the Error

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

Question 1
A IF key_pressed THEN
B SEND interrupt TO printer
C CPU runs keyboard ISR
D ENDIF
Question 2
A WHILE printer_is_printing
B IF paper_tray = empty THEN
C WAIT until CPU asks
D ENDIF
E ENDWHILE
Question 3
A IF mouse_moved THEN
B signal ← software_interrupt
C SEND signal TO CPU
D ENDIF
Question 4
A START data_transfer
B CPU does other tasks
C WHEN transfer_done
D CPU SENDS interrupt
Question 5
A WHEN mouse_clicked
B mouse SENDS interrupt
C CPU runs the keyboard ISR
D CPU resumes previous task

Answer Key

Hardware interrupts
Section A: Quick Questions
Q1
A — A hardware interrupt, sent by the keyboard
Q2
B — A signal from a hardware device telling the CPU it needs attention
Q3
A — The printer sends a hardware interrupt to the CPU
Q4
A — Moving the mouse
Q5
B — A device that has finished transferring data
Section B: Match the Pairs
Q1
keyboard -> interrupt signal -> CPU → Pressing a key on the keyboard sends a hardware interrupt to the CPU so the key press can be dealt with.
Q2
printer: out of paper -> interrupt → A printer running out of paper generates a hardware interrupt to tell the CPU it needs attention.
Q3
Moving the mouse is an event that makes the mouse send a hardware interrupt to the CPU. → mouse moved -> hardware interrupt -> CPU
Q4
A device that finishes a data transfer sends a hardware interrupt so the CPU knows it can carry on. → transfer complete -> hardware interrupt
Q5
The CPU generates the hardware interrupt when a key is pressed. → A hardware interrupt is generated by the hardware device (the keyboard), not by the CPU. The CPU receives the signal and responds to it.
Q6
A hardware interrupt is caused by an error in a program, such as dividing by zero. → An error in a program, such as divide by zero, causes a software interrupt. A hardware interrupt comes from a hardware device such as a keyboard, mouse or printer.
Section C: Definitions
Q1
hardware interrupt — A signal sent by a hardware device, such as a keyboard, mouse or printer, to tell the CPU it needs attention, for example a key press or a printer out of paper.
Section D: Fill in the Blanks
Q1
A hardware interrupt is sent by a device
Q2
IF keyPressed THEN SEND interrupt TO CPU
Q3
IF paperTray = 0 THEN SEND interrupt
Q4
IF transferDone = TRUE THEN SEND interrupt
Q5
IF mouseMoved THEN SEND interrupt TO CPU
Section E: Spot the Error
Q1
B — A hardware interrupt is a signal sent to the CPU, not to another device. The line should be SEND interrupt TO CPU.
Q2
C — The printer does not wait to be asked. A hardware device generates the interrupt itself when it needs attention. The line should be SEND interrupt TO CPU.
Q3
B — Moving the mouse is an event from a hardware device, so it creates a hardware interrupt, not a software interrupt. It should be hardware_interrupt.
Q4
D — The device that finished the data transfer sends the hardware interrupt to the CPU. The CPU does not send it. It should be device SENDS interrupt.
Q5
C — The CPU must run the interrupt service routine for the device that raised the interrupt. A mouse click needs the mouse ISR, not the keyboard ISR.