The worksheetDownload the PDF
Answers

F9.3 Hardware, software and von Neumann

Logic and computer systems · GCSE · OCR J277 1.1.1, AQA 8525 3.4.1, Edexcel 1CP2 3.1.1 · about 15 min

BugBotLab

What this lesson is about

Hardware and software, and the stored program concept in a tiny computer.

Questions 5 marks in all

  1. [1 mark]Which of these is software?

    1. AThe robot's firmware
    2. BThe camera
    3. CThe battery
    4. DThe processor
    Answer: A. Software is the programs; the others are physical parts.
  2. [1 mark]What is the stored program concept?

    1. AProgram instructions and data are held together in the same memory
    2. BPrograms are stored on a separate disk from data
    3. CPrograms are wired into the processor
    4. DEvery program is saved before it runs
    Answer: A. Loading a new program into memory changes the job, with no rewiring.
  3. [1 mark]Which is system software?

    1. AAn operating system
    2. BA web browser
    3. CA game
    4. DA word processor
    Answer: A. System software runs the computer; applications do jobs for the user.
  4. [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)
    Answer:
    42

    LOAD 3 gets 30, ADD 4 adds 12.

  5. [1 mark]How does the processor know which address holds the next instruction?

    1. AThe program counter holds its address
    2. BInstructions are marked differently from data
    3. CIt reads every address in order until it finds one
    4. DThe user types it in
    Answer: A. Memory just holds values; the program counter points to the next instruction.

The task: a stored program

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.

A solution

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.