Logic and computer systems · GCSE · OCR J277 1.1.1, AQA 8525 3.4.1, Edexcel 1CP2 3.1.1 · about 15 min
Hardware and software, and the stored program concept in a tiny computer.
[1 mark]Which of these is software?
[1 mark]What is the stored program concept?
[1 mark]Which is system software?
[1 mark]What does this program print?
memory = ["LOAD 3", "ADD 4", "HALT", 30, 12] acc = memory[int(memory[0].split()[1])] acc = acc + memory[int(memory[1].split()[1])] print(acc)
42
LOAD 3 gets 30, ADD 4 adds 12.
[1 mark]How does the processor know which address holds the next instruction?
Add a SUB instruction to the tiny computer, which subtracts the value at an address from the accumulator. Then put a program in memory that loads 50 from address 6, subtracts 8 from address 7, stores the answer at address 8 and outputs it, so the program prints output: 42. The robot should then drive forward the answer in centimetres, divided by 2, read from memory address 8.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() memory = ["LOAD 6", "ADD 7", "STORE 8", "OUT 8", "HALT", "", 50, 8, 0]
The hint students can ask for: Add one more branch to the processor loop for subtracting, and change the program in memory so it subtracts instead of adds. After the loop ends, read the answer back out of memory and use it to work out how far to drive.
from bugbot import *
connect()
memory = ["LOAD 6", "SUB 7", "STORE 8", "OUT 8", "HALT", "", 50, 8, 0]
acc = 0
pc = 0
while True:
op, *arg = memory[pc].split()
pc = pc + 1
if op == "LOAD":
acc = memory[int(arg[0])]
elif op == "ADD":
acc = acc + memory[int(arg[0])]
elif op == "SUB":
acc = acc - memory[int(arg[0])]
elif op == "STORE":
memory[int(arg[0])] = acc
elif op == "OUT":
print("output:", memory[int(arg[0])])
elif op == "HALT":
break
forward(50, distance=memory[8] / 2)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.