Computer architecture · A level · OCR H446 1.2.4, AQA 7517 4.7.3.5 · about 25 min
OCR's LMC instruction set: tracing and writing programs with selection and iteration, run in Python.
[1 mark]In the LMC, what does BRP do?
[1 mark]Which LMC mnemonic stores the accumulator in a mailbox?
[1 mark]An LMC program is INP, STA 9, INP, SUB 9, OUT, HLT. The inputs are 20 then 35. What is output?
[1 mark]Why are DAT lines put after HLT?
[1 mark]These mailboxes hold an assembled LMC program, run by this code. What does it output?
mailboxes = [901, 308, 508, 902, 209, 308, 802, 0, 0, 1]
acc, pc, inputs = 0, 0, [2]
while True:
ins = mailboxes[pc]
pc += 1
op, xx = ins // 100, ins % 100
if ins == 0: break
elif op == 2: acc -= mailboxes[xx]
elif op == 3: mailboxes[xx] = acc
elif op == 5: acc = mailboxes[xx]
elif op == 8 and acc >= 0: pc = xx
elif ins == 901: acc = inputs.pop(0)
elif ins == 902: print(acc)2 1 0
This is the countdown program: with input 2 it outputs 2, 1 and 0, then the accumulator goes negative and BRP does not branch.
Write an LMC program in the string program. It repeatedly inputs a pair of numbers, first and second, and outputs the larger of the two (either one if they are equal). If the first number of a pair is 0, it stops at once without reading a second number.
The inputs are whole numbers from 0 to 999. The task's inputs are 58, 23, 7, 19, 30, 30, 0, so the program must output OUT 58, OUT 19 and OUT 30, and nothing else. The folded helpers assemble and run_lmc are given: run_lmc prints each output as OUT and the value, and reads each input with input(). The robot does not move.
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.