The CPU checks for interrupts after each cycle

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

The CPU checks for interrupts after each cycle

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. When does the CPU check whether an interrupt signal has arrived?
A Only when the computer is switched off
B At the end of each fetch-decode-execute cycle
2. The CPU is halfway through executing an instruction when an interrupt signal arrives. What happens?
A The CPU finishes the current instruction, then checks and handles the interrupt
B The CPU stops mid-instruction and handles the interrupt straight away
3. At the end of a cycle the CPU finds NO interrupt signal. What does it do next?
A It fetches the next instruction and carries on as normal
B It stops and waits until an interrupt arrives
4. At the end of a cycle the CPU finds an interrupt signal. What does it do before fetching the next program instruction?
A It switches to handling the interrupt
B It ignores the interrupt and fetches the next instruction
5. Which statement about the interrupt check is correct?
A It is only done when the user presses a key
B It is done once every cycle, whether or not an interrupt has occurred

Match the Pairs

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

Left columnRight column
1IF interrupt_signal = TRUE THEN AIF interrupt found THEN handle interrupt BEFORE next fetch
2ELSE fetch next instruction BNo interrupt is present, so the CPU carries on as normal with the next fetch-decode-execute cycle
3The CPU only checks for an interrupt after the current instruction has finished, at the end of the cycle Cfetch, decode, execute, THEN check interrupt
4If an interrupt is found during the check, the CPU switches to handling it before fetching the next instruction DAt the end of a cycle, the CPU checks whether an interrupt has arrived and, if it has, switches to handling it
5check for interrupt, then fetch, decode, execute EThe interrupt check is placed at the start of the cycle. The CPU checks at the END of each cycle, after the current instruction has been executed.
6No interrupt found, so the CPU stops and waits FIf there is no interrupt, the CPU does not stop. It carries on as normal and fetches the next instruction.

Definitions

interrupt check

Fill in the Blanks

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

1.
execute() __ interrupt = TRUE THEN handle_interrupt()
2.
execute() IF interrupt = ____ THEN handle_interrupt()
3.
IF interrupt = _____ THEN fetch_next_instruction() ENDIF
4.
decode() execute() _______________()
5.
IF interrupt THEN handle() ____ fetch()

Spot the Error

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

Question 1
A REPEAT
B FETCH instruction
C DECODE and EXECUTE
D IF no interrupt THEN run ISR
E UNTIL power off
Question 2
A FINISH current instruction
B SKIP the interrupt check
C IF none THEN FETCH next
Question 3
A Interrupt signal arrives
B CPU finishes the instruction
C CPU ignores the signal
Question 4
A IF no interrupt THEN
B FETCH next instruction
C ELSE ignore the interrupt
D ENDIF
Question 5
A AT END OF the whole program
B CHECK interrupt signal
C IF none THEN carry on

Answer Key

The CPU checks for interrupts after each cycle
Section A: Quick Questions
Q1
B — At the end of each fetch-decode-execute cycle
Q2
A — The CPU finishes the current instruction, then checks and handles the interrupt
Q3
A — It fetches the next instruction and carries on as normal
Q4
A — It switches to handling the interrupt
Q5
B — It is done once every cycle, whether or not an interrupt has occurred
Section B: Match the Pairs
Q1
IF interrupt_signal = TRUE THEN → At the end of a cycle, the CPU checks whether an interrupt has arrived and, if it has, switches to handling it
Q2
ELSE fetch next instruction → No interrupt is present, so the CPU carries on as normal with the next fetch-decode-execute cycle
Q3
The CPU only checks for an interrupt after the current instruction has finished, at the end of the cycle → fetch, decode, execute, THEN check interrupt
Q4
If an interrupt is found during the check, the CPU switches to handling it before fetching the next instruction → IF interrupt found THEN handle interrupt BEFORE next fetch
Q5
check for interrupt, then fetch, decode, execute → The interrupt check is placed at the start of the cycle. The CPU checks at the END of each cycle, after the current instruction has been executed.
Q6
No interrupt found, so the CPU stops and waits → If there is no interrupt, the CPU does not stop. It carries on as normal and fetches the next instruction.
Section C: Definitions
Q1
interrupt check — At the end of each fetch-decode-execute cycle the CPU checks for an interrupt signal. If none, it fetches the next instruction; if one, it switches to handling it first.
Section D: Fill in the Blanks
Q1
execute() IF interrupt = TRUE THEN handle_interrupt()
Q2
execute() IF interrupt = TRUE THEN handle_interrupt()
Q3
IF interrupt = FALSE THEN fetch_next_instruction() ENDIF
Q4
decode() execute() check_interrupt()
Q5
IF interrupt THEN handle() ELSE fetch()
Section E: Spot the Error
Q1
D — The CPU only switches to the interrupt service routine when an interrupt IS present. The line should be IF interrupt THEN run ISR.
Q2
B — The CPU checks for an interrupt signal at the end of every cycle, so it must not skip the check. The line should be CHECK for interrupt signal.
Q3
C — After the current instruction has finished, the CPU checks the interrupt signal and does not ignore it. The line should be CPU then checks the signal.
Q4
C — If an interrupt is present, the CPU switches to handling it before fetching the next instruction. It does not ignore it. The line should be ELSE handle the interrupt.
Q5
A — The interrupt check happens at the end of each fetch-decode-execute cycle, not only when the whole program ends. The line should be AT END OF each cycle.