Hardware interrupts compared with software interrupts

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

Hardware interrupts compared with software interrupts

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A user presses a key on the keyboard while a program is running. What type of interrupt is this?
A Software interrupt
B Hardware interrupt
2. A program tries to divide a number by zero. What type of interrupt is generated?
A Software interrupt
B Hardware interrupt
3. Which statement correctly describes the SOURCE of a hardware interrupt?
A The running program itself, such as a divide by zero error
B A device outside the running program, such as a mouse
4. Which statement correctly describes the SOURCE of a software interrupt?
A The running program or process itself
B A peripheral device such as a keyboard
5. The user moves the mouse while a video plays. Which type of interrupt is this?
A Hardware interrupt
B Software interrupt

Match the Pairs

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

Left columnRight column
1Key pressed on the keyboard while a program runs Amouse moved -> interrupt signal sent to CPU
2result = 10 / 0 BA key press comes from the keyboard device outside the program, so it is a hardware interrupt, not a software interrupt
3A hardware interrupt is generated by a device and not by the program, for example when the mouse is moved CA software interrupt, because the running program causes the error itself
4A software interrupt is generated by the program or process, for example when two programs try to use the same memory DDivision by zero is caused by the running program, so it is a software interrupt, not a hardware interrupt
5Division by zero is a hardware interrupt because the CPU does the maths EA hardware interrupt, because the signal comes from a device outside the running program
6A key press is a software interrupt because the user is running the program Fmemory conflict -> interrupt raised by software

Definitions

hardware interrupt vs software interrupt

Fill in the Blanks

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

1.
Event: key press Type: ________ interrupt
2.
Event: division by zero Type: ________ interrupt
3.
Software source: the running _______
4.
Event | Type key press | hardware memory conflict | ________
5.
Hardware: from outside the program Software: from ______ the program

Spot the Error

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

Question 1
A event ← "key press"
B source ← "running program"
C type ← "hardware interrupt"
D OUTPUT type
Question 2
A event ← "divide by zero"
B source ← "running program"
C type ← "hardware interrupt"
D OUTPUT type
Question 3
A event ← "memory conflict"
B source ← "mouse device"
C type ← "hardware interrupt"
Question 4
A IF source = "device" THEN
B type ← "software"
C ELSE
D type ← "software"
E ENDIF
Question 5
A INPUT event
B source ← GetSource(event)
C IF source = "program" THEN
D OUTPUT "hardware interrupt"
E ENDIF

Answer Key

Hardware interrupts compared with software interrupts
Section A: Quick Questions
Q1
B — Hardware interrupt
Q2
A — Software interrupt
Q3
B — A device outside the running program, such as a mouse
Q4
A — The running program or process itself
Q5
A — Hardware interrupt
Section B: Match the Pairs
Q1
Key pressed on the keyboard while a program runs → A hardware interrupt, because the signal comes from a device outside the running program
Q2
result = 10 / 0 → A software interrupt, because the running program causes the error itself
Q3
A hardware interrupt is generated by a device and not by the program, for example when the mouse is moved → mouse moved -> interrupt signal sent to CPU
Q4
A software interrupt is generated by the program or process, for example when two programs try to use the same memory → memory conflict -> interrupt raised by software
Q5
Division by zero is a hardware interrupt because the CPU does the maths → Division by zero is caused by the running program, so it is a software interrupt, not a hardware interrupt
Q6
A key press is a software interrupt because the user is running the program → A key press comes from the keyboard device outside the program, so it is a hardware interrupt, not a software interrupt
Section C: Definitions
Q1
hardware interrupt vs software interrupt — A hardware interrupt comes from a device outside the program (key press, mouse move); a software interrupt comes from the running program itself (divide by zero, memory conflict).
Section D: Fill in the Blanks
Q1
Event: key press Type: hardware interrupt
Q2
Event: division by zero Type: software interrupt
Q3
Software source: the running program
Q4
Event | Type key press | hardware memory conflict | software
Q5
Hardware: from outside the program Software: from inside the program
Section E: Spot the Error
Q1
B — A key press is signalled by the keyboard, a device outside the running program. The source should be "keyboard device", not "running program".
Q2
C — Divide by zero is caused by the running program itself, so it is a software interrupt. Line 3 should be type ← "software interrupt".
Q3
A — The source is a mouse device and the type is hardware, so the event must be a hardware event such as "mouse move". A memory conflict is a software interrupt.
Q4
B — If the signal comes from a device outside the program, it is a hardware interrupt. Line 2 should be type ← "hardware".
Q5
C — The output says hardware interrupt, which comes from a device. The condition should test source = "device", because a program source means a software interrupt.