How Computers Work

Lesson 4 of 7

The CPU

Step inside the brain of the computer and discover how the Central Processing Unit executes instructions.

🟡 Intermediate 75 XP

Learn it

The Central Processing Unit, or CPU, is often called the 'brain' of the computer. It is a tiny silicon chip that carries out billions of instructions every single second!

The CPU does its job using a never-ending cycle called the Fetch-Decode-Execute cycle. First, it fetches an instruction from memory. Next, it decodes what the instruction means. Finally, it executes the instruction.

Inside the CPU, you will find specialised parts: the ALU (which does all the math and logic), the Control Unit (which acts like a traffic cop directing data), and Cache (super-fast memory).

Key terms

CPU
Central Processing Unit; the primary silicon microchip that fetches, decodes, and executes program instructions.
Fetch-Decode-Execute Cycle
The fundamental operational cycle of the CPU: retrieving an instruction from RAM, interpreting it, and carrying it out.
Arithmetic Logic Unit (ALU)
The CPU sub-component that carries out arithmetic calculations (+, -, *, /) and logical comparisons (AND, OR, NOT).
Control Unit (CU)
The CPU sub-component that directs the flow of data and instructions between CPU components and system peripherals.
Clock Speed
The frequency at which a CPU executes cycles, measured in Hertz (Hz) or Gigahertz (GHz).

The Fetch-Decode-Execute Cycle

Every computer program breaks down into machine instructions processed in this continuous loop.

  1. 11. Fetch: The CPU reads the address in the Program Counter and fetches the next instruction from RAM into the instruction register.
  2. 22. Decode: The Control Unit splits the instruction into an opcode (the operation) and operand (the data), determining what action is required.
  3. 33. Execute: The ALU performs calculations or data transfers take place between registers and system memory.
  4. 44. Repeat: The Program Counter increments by one to point to the subsequent instruction, and the cycle repeats billions of times a second.

Simulating the Fetch-Decode-Execute Cycle

python# A simplified virtual CPU instruction emulator
memory = [
    ('LOAD', 5),    # Load value 5 into register A
    ('ADD', 12),    # Add 12 to register A
    ('PRINT', None) # Display register A
]

register_a = 0
pc = 0  # Program Counter

while pc < len(memory):
    # 1. FETCH
    instruction, operand = memory[pc]
    
    # 2. DECODE & 3. EXECUTE
    if instruction == 'LOAD':
        register_a = operand
    elif instruction == 'ADD':
        register_a += operand
    elif instruction == 'PRINT':
        print('CPU Accumulator Output:', register_a)
    
    # Advance Program Counter
    pc += 1

This Python simulation reflects how a real processor steps sequentially through instructions, decoding opcodes and updating internal registers.

Try it

Predict what this CPU emulation script will output to the terminal when executed.

pythonaccumulator = 10
instructions = [('ADD', 5), ('SUB', 3), ('MUL', 2)]

for opcode, val in instructions:
    if opcode == 'ADD':
        accumulator += val
    elif opcode == 'SUB':
        accumulator -= val
    elif opcode == 'MUL':
        accumulator *= val

print(accumulator)

Challenge

Explain why a 3.5 GHz quad-core CPU might perform faster on video editing than a 4.0 GHz dual-core CPU.

Pick whichever way suits you — every mode earns the same bonus XP.

Write at least 40 more characters to submit.

Mark your own work

Guided walkthrough — 0/5 clues revealed

  1. Clue 1 locked — reveal it only if you get stuck.
  2. Clue 2 locked — reveal it only if you get stuck.
  3. Clue 3 locked — reveal it only if you get stuck.
  4. Clue 4 locked — reveal it only if you get stuck.
  5. Clue 5 locked — reveal it only if you get stuck.

Each clue costs 4 XP (never below 19 XP). You'd earn 38 XP right now.

Extension: Research CPU cache levels (L1, L2, and L3) and explain why cache is built directly onto the CPU die instead of just using standard RAM.

Quiz time

Question 1 of 4Score 0

What is the primary role of the Arithmetic Logic Unit (ALU)?