What Is a CPU?
CPU Basics · Foundations track
3 min read
In this module
The Brain of the Computer
The CPU, or Central Processing Unit, is the component that actually executes the instructions that make software run. Every time you open an application, type a character, or scroll a page, the CPU is doing the underlying work. It reads instructions from memory, works out what each one means, and carries it out.
That's really what a CPU does, over and over, billions of times per second: fetch, decode, and execute instructions.
Here are the main parts you'll meet in this module and how they connect. The bold path is the one every instruction takes first: the program counter supplies an address, memory sends back the instruction stored there, and the control unit decodes it.
Don't worry about memorising it now. Each box gets its own lesson, and you can come back to this picture whenever you lose track of where something lives.
Fetch, Decode, Execute
Every program you run lives in memory as a sequence of instructions. The CPU grinds through them in a cycle:
- Fetch the next instruction from memory.
- Decode it. What's it asking for? Add two numbers? Store a value? Jump elsewhere in the program?
- Execute the operation.
That three-step loop is the fundamental heartbeat of every processor ever built. We'll dig into it later in this module, where saving the result gets its own fourth step, writeback, split off from execute.
You can watch it now. The simulator below holds a two-instruction program for a small teaching CPU: put 5 in register R0, then add 3 to it. Press Step once per instruction. Watch the PC register move from 0 to 2 to 4 (each instruction here is two bytes long), and watch R0 change only when an instruction executes.
For the best simulation experience, use a desktop browser.
Assembly
Registers
ALU
Memory
| Address | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 10 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 20 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 30 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 40 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 50 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 60 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 70 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 80 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 90 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| A0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| B0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| C0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| D0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| E0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| F0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
Pipeline
Cycle 0The CPU operates in a continuous fetch-decode-execute cycle. It reads an instruction from memory, determines what that instruction means, and then carries it out. This cycle repeats for every single instruction a program contains.
Clock Speed and Cycles
The CPU doesn't work at a random pace. It's driven by a clock, an electrical signal that ticks at a fixed rate. Each tick is one clock cycle, and most operations take one or more cycles to finish.
Clock speed is measured in hertz. A 3 GHz processor ticks three billion times per second. Faster clocks generally mean more instructions per second, but clock speed alone doesn't tell the whole performance story. Architecture matters too.
A Brief History
The earliest computers used vacuum tubes as switches: large, hot, and notoriously unreliable. In the late 1950s, transistors displaced vacuum tubes, making computers smaller and far more dependable. The integrated circuit followed soon after (Jack Kilby's 1958 invention), packing many transistors onto a single chip. Modern CPUs cram billions of transistors onto a piece of silicon smaller than a postage stamp.
The fundamental idea hasn't budged. The CPU still fetches, decodes, and executes. The hardware just got extraordinarily fast.
Try the Simulations
Add Two Numbers
Load two values into registers and add them together. The simplest possible program.
Understanding CPU Flags
Run several comparisons and watch how the CPU flags change. Equal values set the zero flag, smaller-than sets the negative flag - flags are how the CPU remembers comparison results.