The answersDownload the PDF
Worksheet

F9.4 The CPU and fetch-execute

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

BugBotLab
NameClassDate

What this lesson is about

The ALU, control unit, registers and buses, and tracing the fetch-decode-execute cycle.

Questions 6 marks in all

  1. [1 mark]Which register holds the address of the next instruction to fetch?

    1. AProgram counter
    2. BMemory data register
    3. CAccumulator
    4. DMemory address register
  2. [1 mark]What does the ALU do?

    1. ACarries out arithmetic and logic operations
    2. BDecodes instructions
    3. CHolds the address to read from
    4. DSends the clock pulse
  3. [1 mark]Put these steps of the cycle in order.

    Number the lines 1 to 4 to put them in the right order.

    1. The instruction is executed
    2. The address in the PC is copied to the MAR
    3. The instruction at that address is copied to the MDR
    4. The control unit decodes the instruction
  4. [1 mark]Which bus carries addresses from the CPU to memory?

    1. AAddress bus
    2. BData bus
    3. CControl bus
    4. DUSB
  5. [1 mark]What does the memory data register hold?

    1. AThe data or instruction just read from memory, or about to be written
    2. BThe address of the next instruction
    3. CThe result of the last calculation only
    4. DThe clock speed
  6. [1 mark]What does this program print?

    pc = 4
    mar = pc
    pc = pc + 1
    print(mar, pc)

The task: trace the cycle

Complete the fetch-decode-execute loop so it runs the program in memory and supports LOAD, ADD, SUB, STORE, OUT and HALT. During each fetch, print fetch <MAR>: <instruction> (for example fetch 0: LOAD 6). The program outputs output: 35.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

memory = ["LOAD 6", "SUB 7", "ADD 8", "STORE 9", "OUT 9", "HALT", 40, 12, 7, 0]
pc = mar = acc = 0
mdr = None

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/f9-4-the-cpu-and-fetch-execute/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Add a JUMPZ a instruction that jumps to address a if the accumulator is 0. Write a countdown program with it.
  2. Count how many fetch-execute cycles the program takes, and how many would run in one second at 1 GHz.
  3. Encode each instruction as an 8-bit number, with a 4-bit opcode and a 4-bit address, and print the memory as binary.