Processor Fundamentals and Assembly Language: Question 3
Syllabus 4.1
A washing machine's embedded computer runs a wash-cycle-timing program in a continuous fetch-execute cycle. A "door open" sensor can generate a hardware interrupt at any moment while this program is running, and the processor must respond to it correctly without permanently losing its place in the wash-cycle program.
(a) State when, in relation to the fetch-execute cycle, the CPU checks whether an interrupt is pending. [1]
(b) Describe the sequence of actions the CPU carries out immediately after it detects the pending interrupt, up to the point where the interrupt service routine (ISR) begins to execute. [3]
(c) Explain what must happen once the ISR has finished executing, so that the wash-cycle-timing program resumes correctly. [2]
Show worked solution Hide worked solution
Worked solution
Part (a): When interrupts are checked
The CPU checks whether an interrupt is pending at the end of the fetch-execute cycle. That is, once the current instruction has been fully executed, and before the next instruction is fetched.
[1 mark]
Part (b): Responding to the interrupt
Once the current instruction has finished and a pending interrupt (the door-open signal) is detected, the CPU:
- Finishes executing the current instruction (it never stops in the middle of one).
- Saves its current state, the contents of the PC and other registers, typically onto a stack, so that the wash-cycle program’s exact position is preserved.
- Loads the start address of the interrupt service routine (ISR) into the PC, so the next fetch-execute cycle fetches the ISR’s first instruction instead of continuing the wash-cycle program.
[3 marks]: 1 for completing the current instruction first, 1 for saving the state (PC and registers, e.g. onto a stack), 1 for loading the ISR’s address into the PC.
Part (c): Resuming after the ISR
After the ISR has finished executing, the previously saved register values, including the PC, are restored from the stack. Because the PC is restored to the address of the instruction that would have been fetched next in the wash-cycle program, the fetch-execute cycle resumes at exactly that instruction, so the wash-cycle-timing program continues correctly, as though the interruption had never happened.
[2 marks]: 1 for restoring the saved registers (including the PC) from the stack, 1 for identifying that this causes execution to resume at the correct next instruction of the interrupted program.
Final answers
- (a) At the end of the current fetch-execute cycle, once the current instruction has finished executing.
- (b) Finish the current instruction; save the state (PC and registers) onto a stack; load the ISR’s start address into the PC.
- (c) Restore the saved registers (including the PC) from the stack, so the wash-cycle program resumes at the correct next instruction.