What happens as a result of an interrupt

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

What happens as a result of an interrupt

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A user presses a key while a word processor is open. What does the ISR do?
A It reads the character and passes it to the program
B It shuts down the computer and restarts it
2. A user moves the mouse. What is the result of the interrupt?
A The current program is deleted from memory
B The pointer position on the screen is updated
3. A program tries to divide a number by zero. What can the ISR do?
A Return the answer 0 and hide the problem
B Show an error message or stop the faulty program
4. Two processes try to use the same area of memory at once (a memory conflict). What can happen?
A One process is stopped or made to wait
B Both processes overwrite the memory at the same time
5. Once the ISR has finished handling an interrupt, what does the CPU do next?
A Returns to the task it was interrupted from and carries on
B Starts the interrupted program again from the beginning

Match the Pairs

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

Left columnRight column
1key press interrupt -> ISR reads the character AISR finished -> restore state -> resume task
2mouse move interrupt -> ISR updates pointer BThe ISR action is wrong for the event. A divide by zero is dealt with by showing an error message or stopping the faulty program, not by reading a key press.
3Dividing by zero causes an interrupt, and the ISR shows an error message or stops the faulty program CThe ISR works out the new position and the pointer on the screen is moved to it
4When the ISR has finished, the CPU goes back to the task it was running before the interrupt DThe ISR reads the key that was pressed and passes the character to the program that is waiting for it
5divide by zero interrupt -> ISR reads a key press EIF divisor = 0 THEN ISR shows error / stops program
6ISR finished -> CPU stops and never runs the task again FAfter the ISR the CPU should return to the interrupted task and carry on. It does not stop for good.

Definitions

interrupt outcome

Fill in the Blanks

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

1.
IF event = "key press" THEN character ← _______() passToProgram(character)
2.
IF event = "mouse move" THEN _____________(newX, newY) ENDIF
3.
IF event = "divide by zero" THEN _________("Cannot divide by zero") stopProgram()
4.
IF event = "memory conflict" THEN ___________(faultyProcess) ENDIF
5.
restoreState() ______(interruptedTask)

Spot the Error

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

Question 1
A INTERRUPT key_press
B ISR: READ key FROM monitor
C PASS key TO program
D RESUME previous task
Question 2
A INTERRUPT mouse_move
B ISR: SHUT DOWN the computer
C REDRAW pointer on screen
D RESUME previous task
Question 3
A INTERRUPT mouse_move
B ISR: SHOW error message
C STOP faulty program
D CPU RESUMES other tasks
Question 4
A INTERRUPT memory_conflict
B ISR: FIND clashing process
C SPEED UP that process
D RESUME the interrupted task
Question 5
A INTERRUPT key_press
B SAVE state of CPU
C ISR: READ key
D PASS key TO printer
E RESUME interrupted task

Answer Key

What happens as a result of an interrupt
Section A: Quick Questions
Q1
A — It reads the character and passes it to the program
Q2
B — The pointer position on the screen is updated
Q3
B — Show an error message or stop the faulty program
Q4
A — One process is stopped or made to wait
Q5
A — Returns to the task it was interrupted from and carries on
Section B: Match the Pairs
Q1
key press interrupt -> ISR reads the character → The ISR reads the key that was pressed and passes the character to the program that is waiting for it
Q2
mouse move interrupt -> ISR updates pointer → The ISR works out the new position and the pointer on the screen is moved to it
Q3
Dividing by zero causes an interrupt, and the ISR shows an error message or stops the faulty program → IF divisor = 0 THEN ISR shows error / stops program
Q4
When the ISR has finished, the CPU goes back to the task it was running before the interrupt → ISR finished -> restore state -> resume task
Q5
divide by zero interrupt -> ISR reads a key press → The ISR action is wrong for the event. A divide by zero is dealt with by showing an error message or stopping the faulty program, not by reading a key press.
Q6
ISR finished -> CPU stops and never runs the task again → After the ISR the CPU should return to the interrupted task and carry on. It does not stop for good.
Section C: Definitions
Q1
interrupt outcome — What the ISR does depends on the event: it reads a key press, updates the pointer, shows an error or stops a faulty program. Then the CPU resumes the task it was running.
Section D: Fill in the Blanks
Q1
IF event = "key press" THEN character ← readKey() passToProgram(character)
Q2
IF event = "mouse move" THEN updatePointer(newX, newY) ENDIF
Q3
IF event = "divide by zero" THEN showError("Cannot divide by zero") stopProgram()
Q4
IF event = "memory conflict" THEN stopProcess(faultyProcess) ENDIF
Q5
restoreState() resume(interruptedTask)
Section E: Spot the Error
Q1
B — A key press is read from the keyboard, not the monitor. The monitor is an output device, so it cannot supply the character. The line should be ISR: READ key FROM keyboard.
Q2
B — Moving the mouse does not need the computer to shut down. The ISR just updates the pointer position, so the line should be ISR: UPDATE pointer position.
Q3
A — The ISR here shows an error message and stops the faulty program. That outcome belongs to a divide by zero interrupt, not a mouse move. The line should be INTERRUPT divide_by_zero.
Q4
C — With a memory conflict, the clashing process is stopped or made to wait so it stops interfering. Speeding it up would make the clash worse. The line should be STOP or WAIT that process.
Q5
D — The character that was read is passed to the program the user is typing into, not to a printer. The line should be PASS key TO program.