AxoPrep

Computer Science

A1.1 Computer hardware and operation

Watch the lessonIB Computer Science CPU: ALU, CU & Registers (MAR vs MDR)

How the CPU, its registers and the memory hierarchy cooperate through the fetch-decode-execute cycle, and how GPUs, storage and compression fit around them. Study guide, 5 practice questions with markschemes and 10 flashcards. Free.

CPU components and their roles · GPU versus CPU · primary memory types (RAM, ROM, cache, registers) · fetch-decode-execute cycle · secondary storage · data compression · (HL) pipelining in multi-core processors

Practise all 5 questions Study 10 flashcards ▶ Watch the video lesson

Study guide

The processor and its parts

The central processing unit (CPU) runs program instructions one after another. Three parts do the work:

RegisterHolds
Program counter (PC)Address of the next instruction to fetch
Memory address register (MAR)Address currently being read from or written to
Memory data register (MDR)Data or instruction just read, or about to be written
Current instruction register (CIR)Instruction being decoded and executed
Accumulator (ACC)Intermediate results from the ALU

Data moves between the CPU and RAM along the address bus (one direction, CPU to memory), the data bus (both directions) and the control bus (read/write and timing signals).

The fetch-decode-execute cycle

flowchart TD
  A[Copy PC into MAR] --> B[Read memory at MAR address]
  B --> C[Instruction arrives in MDR]
  C --> D[Copy MDR into CIR; PC = PC + 1]
  D --> E[CU decodes the instruction in CIR]
  E --> F[Execute: ALU works, memory is read or written, or PC is changed by a jump]
  F --> A

A jump or loop instruction works by overwriting the PC with a new address during the execute stage, so the next fetch comes from somewhere else.

Memory: speed versus size

Going outward from the CPU, memory gets bigger, cheaper per byte and slower: registers -> cache -> RAM -> secondary storage.

CPU versus GPU

A CPU has a few powerful cores tuned for fast sequential work and complex branching. A GPU has thousands of simpler cores that run the same operation on many pieces of data at once. Rendering pixels and training machine-learning models (huge matrix multiplications) suit a GPU; running an operating system, handling user input or code with lots of if decisions suits a CPU.

Secondary storage

TypeHow it storesStrengthsWeaknesses
Magnetic (HDD)Magnetised platters, moving headCheap per GB, largeSlow seek, fragile moving parts
Solid state (SSD, flash)Charge in transistor cellsFast, silent, shock-resistantDearer per GB, limited write cycles
Optical (DVD, Blu-ray)Pits read by a laserCheap to distributeSmall capacity, slow

Data compression

Pipelining in multi-core processors (HL)

Pipelining overlaps stages: while instruction 1 executes, instruction 2 is decoded and instruction 3 is fetched. With \(k\) stages of one cycle each and \(n\) instructions and no stalls:

\[\text{without pipeline} = n \times k \qquad \text{with pipeline} = k + (n - 1)\]

Example: 5 stages, 20 instructions gives 100 cycles without pipelining but 24 with it. Stalls happen when an instruction needs a result not yet produced (data hazard) or after a branch, when already-fetched instructions must be thrown away. Each core of a multi-core CPU has its own pipeline, so independent threads run truly in parallel, but a single sequential task does not speed up just by adding cores.

Common mistakes

Exam tips

Cheat sheet

Key definitions

Arithmetic logic unit (ALU)

The part of the CPU that carries out arithmetic, comparisons and bitwise logic operations.

Control unit (CU)

The part of the CPU that decodes instructions and issues timing and control signals to the other components.

Program counter (PC)

Register holding the memory address of the next instruction to be fetched.

Memory address register (MAR)

Register holding the address of the memory location about to be read or written.

Memory data register (MDR)

Register that temporarily holds data or an instruction moving between memory and the CPU.

Cache

Small, very fast memory close to the CPU that keeps copies of frequently or recently used data and instructions.

Volatile memory

Memory whose contents are lost when power is removed, such as RAM.

Lossless compression

Reducing file size in a way that lets the exact original data be reconstructed.

Lossy compression

Reducing file size by permanently removing data judged less important.

Pipelining (HL)

Overlapping the stages of several instructions so a new instruction can start before the previous one finishes.

Practice questions

SLPaper 1Foundation

Question 1

(a) [2]

Outline the role of the arithmetic logic unit (ALU) in a processor.

Markscheme
  • 1 Carries out arithmetic operations such as addition and subtraction
  • 1 Carries out logical operations / comparisons such as AND, OR, greater than
(b) [2]

Outline the role of the control unit (CU).

Markscheme
  • 1 Decodes instructions fetched from memory
  • 1 Sends control signals to coordinate other components (ALU, memory, registers, buses)
(c) [1]

Identify the register that holds the address of the next instruction to be fetched.

Markscheme
  • 1 Program counter (PC)
SLPaper 1Standard

Question 2

(a) [4]

Describe the fetch stage of the fetch-decode-execute cycle, referring to the program counter (PC), memory address register (MAR) and memory data register (MDR).

Markscheme
  • 1 The address in the PC is copied into the MAR
  • 1 The instruction at that address is read from memory (via the data bus) into the MDR
  • 1 The instruction is copied from the MDR to the current instruction register (CIR)
  • 1 The PC is incremented to point to the next instruction
(b) [1]

A program jumps back to the start of a loop. State what happens to the value in the PC when the jump instruction is executed.

Markscheme
  • 1 The PC is overwritten with the address of the loop's first instruction (the jump target)
SLPaper 1Standard

Question 3

(a) [3]

A laptop has 16 GB of RAM and 8 MB of cache. Explain why adding cache improves performance even though it is much smaller than RAM.

Markscheme
  • 1 Cache is faster (lower access time) than RAM / is on or very close to the CPU
  • 1 It stores frequently or recently used instructions and data
  • 1 So most requests are served from cache (cache hits), reducing waiting for slower RAM
(b) [1]

State one difference between RAM and ROM.

Markscheme
  • 1 RAM is volatile (loses contents without power) while ROM is non-volatile / RAM is read-write while ROM is read-only in normal use
(c) [2]

Explain why the boot-up instructions of a smart thermostat are stored in ROM rather than RAM.

Markscheme
  • 1 They must be available as soon as power is switched on
  • 1 ROM keeps its contents without power (non-volatile) and they should not be accidentally changed

Key facts

What does the ALU do?

Performs arithmetic (add, subtract) and logic operations (AND, OR, comparisons) on data.

What does the control unit do?

Decodes instructions and sends control signals that coordinate the ALU, memory, registers and buses.

What is held in the program counter (PC)?

The memory address of the next instruction to be fetched.

MAR vs MDR

MAR holds the address being read or written; MDR holds the data or instruction being transferred to or from that address.

Fetch stage in one line

PC → MAR, memory → MDR, MDR → CIR, then PC is incremented.

Why does cache speed up a CPU?

It is small, very fast memory close to the CPU that keeps frequently used data and instructions, so fewer slow RAM accesses are needed.