Computer architecture · A level · OCR H446 1.2.1, AQA 7517 4.7.3.6 · about 20 min
Sources of interrupts, polling, the check at the end of each cycle, saving the volatile environment on a stack, and priorities.
[1 mark]When does the processor check for an interrupt?
[1 mark]Why is the volatile environment saved before an ISR runs?
[1 mark]Put the handling of an interrupt in order.
Number the lines 1 to 6 to put them in the right order.
The address of the ISR is loaded into the PCThe registers are pushed onto the stackThe registers are popped off the stack and the program resumesThe current instruction finishes executingThe processor checks for interrupts and finds one of higher priorityThe ISR runs[1 mark]Why is a stack the right structure for saving registers when interrupts are nested?
[1 mark]Which is a disadvantage of polling compared with interrupts?
Simulate a processor that is interrupted by a timer. The main program runs 12 cycles. In each cycle it drives forward 3 cm, adds 3 to acc, and adds 1 to pc, in that order.
At the end of any cycle after which pc is a multiple of 4 (so after cycles 4, 8 and 12), the timer interrupts. Handle it like this:
1. Save the volatile environment by pushing pc, then acc, onto the list stack, and print saved PC=4 ACC=12 (with the real values).
2. Run the ISR. It uses the accumulator as its working register: set acc to 200 plus 100 times the number of interrupts so far including this one (300, then 400, then 500), and play acc as a tone for 0.2 seconds.
3. Restore the registers by popping them off stack in the reverse order, and print restored PC=4 ACC=12.
After the 12 cycles, print done PC=12 ACC=36, using the values in the registers.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
pc = 0
acc = 0
stack = []
while pc < 12:
forward(50, distance=3)
acc = acc + 3
pc = pc + 1
print(f"done PC={pc} ACC={acc}")Plan your program here, then type it in and press Run.