Interrupt service routine (ISR)

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

Interrupt service routine (ISR)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which describes an interrupt service routine (ISR)?
A A device that sends signals to the CPU to ask for attention
B A small program the CPU runs to deal with one particular interrupt
2. How many ISRs are there for the different types of interrupt?
A One single ISR handles every type of interrupt
B A different ISR for each type of interrupt
3. Where are ISRs kept so they are ready to run?
A In memory
B Only on the keyboard or mouse that causes the interrupt
4. Which part of the computer chooses which ISR to run?
A The operating system
B The keyboard
5. Why is an ISR kept short?
A So the CPU can return quickly to what it was doing
B So the ISR can run forever without stopping

Match the Pairs

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

Left columnRight column
1ISR AAn ISR should be short so the CPU can return quickly to what it was doing.
2ISR_keyboard() and ISR_printer() BEach type of interrupt has its own ISR, because each one needs different instructions to deal with it.
3The operating system chooses which ISR to run for the interrupt that has occurred Cinterrupt = printer_error run ISR_printer_error
4An ISR is short so the CPU can return quickly to the task it was doing DA different ISR for each type of interrupt
5One ISR is used to deal with every type of interrupt EA small program the CPU runs to deal with one particular interrupt
6The ISR is a long program that takes a long time to finish before the CPU returns to its task FISR_keypress read key store in buffer return to task

Definitions

interrupt service routine (ISR)

Fill in the Blanks

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

1.
IF interrupt = KEYBOARD THEN ____ keyISR
2.
IF interrupt = _____ THEN CALL mouseISR
3.
DECLARE ISRtable : _____[1:5] OF STRING
4.
interruptType ← GetInterrupt() CALL ISRtable[_____________]
5.
PROCEDURE mouseISR() OUTPUT "Mouse clicked" ____________

Spot the Error

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

Question 1
A CASE OF interrupt
B KEYBOARD: CALL key_ISR
C PRINTER: CALL key_ISR
D ENDCASE
Question 2
A PROCEDURE keyboard_ISR()
B READ key FROM keyboard
C ADD key TO input_buffer
D WAIT FOR next_key
E ENDPROCEDURE
Question 3
A STORE ISR_table IN HARD_DISK
B table[KEYBOARD] ← key_ISR
C table[MOUSE] ← mouse_ISR
Question 4
A PROCEDURE timer_ISR()
B WAIT 10 SECONDS
C RESET timer
D ENDPROCEDURE
Question 5
A IF interrupt = DIVIDE_BY_ZERO THEN
B CALL error_ISR
C ELSE IF interrupt = KEYPRESS
D CALL key_ISR
E ENDIF

Answer Key

Interrupt service routine (ISR)
Section A: Quick Questions
Q1
B — A small program the CPU runs to deal with one particular interrupt
Q2
B — A different ISR for each type of interrupt
Q3
A — In memory
Q4
A — The operating system
Q5
A — So the CPU can return quickly to what it was doing
Section B: Match the Pairs
Q1
ISR → A small program the CPU runs to deal with one particular interrupt
Q2
ISR_keyboard() and ISR_printer() → A different ISR for each type of interrupt
Q3
The operating system chooses which ISR to run for the interrupt that has occurred → interrupt = printer_error run ISR_printer_error
Q4
An ISR is short so the CPU can return quickly to the task it was doing → ISR_keypress read key store in buffer return to task
Q5
One ISR is used to deal with every type of interrupt → Each type of interrupt has its own ISR, because each one needs different instructions to deal with it.
Q6
The ISR is a long program that takes a long time to finish before the CPU returns to its task → An ISR should be short so the CPU can return quickly to what it was doing.
Section C: Definitions
Q1
interrupt service routine (ISR) — A small program the CPU runs to deal with one particular interrupt. Each type of interrupt has its own ISR, kept in memory, and it is short so the CPU can quickly return to its task.
Section D: Fill in the Blanks
Q1
IF interrupt = KEYBOARD THEN CALL keyISR
Q2
IF interrupt = MOUSE THEN CALL mouseISR
Q3
DECLARE ISRtable : ARRAY[1:5] OF STRING
Q4
interruptType ← GetInterrupt() CALL ISRtable[interruptType]
Q5
PROCEDURE mouseISR() OUTPUT "Mouse clicked" ENDPROCEDURE
Section E: Spot the Error
Q1
C — Each type of interrupt has its own ISR. A printer interrupt must run printer_ISR, not the keyboard ISR.
Q2
D — An ISR must be short so the CPU can return quickly. It should end with RETURN TO previous_task, not wait for more keys.
Q3
A — ISRs are kept in memory (RAM) so they are ready to run straight away. A hard disk is too slow to fetch them from.
Q4
B — An ISR should be short so the CPU can quickly return to its task. Waiting 10 seconds would hold the CPU up. It should be clock ← clock + 1.
Q5
C — The condition is missing THEN. It should be ELSE IF interrupt = KEYPRESS THEN, so the correct ISR is chosen for each interrupt type.