Computer architecture · A level · OCR H446 1.1.1, AQA 7517 4.7.1.1, Eduqas A500QS 2.1 · about 35 min
Build a von Neumann machine with register transfers, addressing modes, flags and memory-mapped I/O that plays a scale on the robot.
[1 mark]In the project machine, storing a value at address 255 plays a note. What is this technique called?
[1 mark]After CMP #700 with 650 in the accumulator, which flags are set in the project machine?
[1 mark]The loop in the project program is 6 instructions long and runs 4 times. With 4 instructions before it and HLT after it, how many fetches are there?
[1 mark]What does this program print?
memory = ['LDA #5', 'ADD 5', 'STA 6', 'HLT', 0, 7, 0]
pc = acc = 0
while True:
cir = memory[pc]
pc += 1
op, _, x = cir.partition(' ')
if op == 'HLT':
break
value = int(x[1:]) if x.startswith('#') else memory[int(x)]
if op == 'LDA': acc = value
elif op == 'ADD': acc += value
elif op == 'STA': memory[int(x)] = acc
print(memory[6], pc)Build the machine described above and run the program. The starter loads the program into memory and sets up the registers; you write everything else, using exactly the variable names pc, mar, mdr, cir and acc for the registers.
- After every fetch, print PC=<pc> MAR=<mar> CIR=<cir> with the register values straight after the four fetch transfers, for example PC=10 MAR=9 CIR=BLT 4.
- Storing to address 254 calls forward(50, distance=<value>); storing to address 255 calls tone(<value>, 0.2).
- When HLT is fetched, stop and print halted after <cycles> cycles, counting every fetch including the HLT, then ACC=<acc> Z=<z> N=<n>.
A working machine drives 10 cm, plays 300, 400, 500 and 600 Hz, prints 29 fetch lines, then halted after 29 cycles and ACC=700 Z=1 N=0.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
memory = [0] * 256
program = [
"LDA #10", "STA 254", "LDA #300", "STA 20", "LDA 20", "STA 255",
"ADD #100", "STA 20", "CMP #700", "BLT 4", "HLT",
]
memory[:len(program)] = program
pc, mar, mdr, cir, acc = 0, 0, 0, "", 0
z, n = 0, 0
cycles = 0Plan your program here, then type it in and press Run.
BEQ.LDX instruction and indexed addressing, and use it to play a tune stored as a list of notes in memory from address 40.