Home / Learn Chip Programming / CPU Architecture: ALU, Registers, Control Unit and Buses

CPU Architecture: ALU, Registers, Control Unit and Buses

Open the CPU and see its parts. Every processor, from an 8 bit AVR to a phone chip, has the same core blocks.

In shortThe CPU has an ALU that calculates, registers that hold values, a control unit that decodes instructions and buses that move data to memory.

Theory in plain words

Blocks of a simple CPUControl unit: decodes the instruction, sends control signalsALU: add, subtract, AND, OR, shift, compareRegisters: R0..Rn, PC (program counter), SP (stack pointer), flagsBuses: address bus, data bus, control bus to memory and peripherals
Blocks of a simple CPU

What it is

The CPU (central processing unit) executes instructions. It has an ALU, registers, a program counter, an instruction register and a control unit, connected to memory by buses.

Why we use it

Understanding the blocks explains why some code is fast, why memory access is slow and what the manual means by words like "flag", "bus" or "pipeline".

How it works

The program counter holds the address of the next instruction. The control unit fetches it from memory, decodes it and tells the ALU and registers what to do. The result goes back to a register or to memory.

Where it is used

  • Every microcontroller and processor
  • Soft cores inside FPGAs (RISC-V, MicroBlaze)
  • Performance tuning and low level debugging

The blocks

BlockJob
ALUarithmetic and logic operations
General registersfast storage for values being used
PC (program counter)address of the next instruction
IR (instruction register)holds the instruction being executed
SP (stack pointer)top of the stack in memory
Status / flags registerZero, Carry, Negative, Overflow bits
Control unitthe conductor: generates all control signals
Address buscarries the address the CPU wants (one direction)
Data buscarries the data (two directions)

Von Neumann vs Harvard

Bus width and address space

With n address lines the CPU can reach 2^n bytes. 16 lines reach 64 KB, 20 lines 1 MB, 32 lines 4 GB. The data bus width (8, 16, 32, 64 bits) decides how much moves at once.

Address bus calculatorTry it Yourself

An Arduino Uno (ATmega328P) has 14 bit program addresses of 16 bit words: 32 KB of Flash. A 32 bit ARM can address 4 GB.

Pipeline in one picture

A pipeline works like a car factory line. While one instruction is being executed, the next is being decoded and the one after is being fetched. A 3 stage pipeline can finish one instruction per clock even though each takes 3 clocks.

Tip:Clock speed alone does not decide performance. Instructions per clock, cache, memory speed and power all matter. A 100 MHz ARM Cortex-M4 can do more useful work per second than a 1 GHz chip that waits for slow memory.

Quick quiz

1. What does the program counter hold?

2. How much can 16 address lines reach?

Common questions

What does the program counter hold?

The address of the next instruction. PC points to the next instruction to fetch.

How much can 16 address lines reach?

64 KB. 2^16 = 65,536 bytes.