Topic 3 · Hardware
The CPU and the fetch-decode-execute cycle
Von Neumann architecture, the CPU's registers and buses, the fetch-decode-execute cycle, and what makes a CPU faster.
What the CPU does
The central processing unit (CPU) processes instructions and data. Programs and their data are held in memory (RAM). The CPU fetches each instruction from memory, works out what it means, and carries it out, billions of times a second.
In the Von Neumann architecture, instructions and data are stored together in the same memory, and the CPU works through them one instruction at a time.
Inside the CPU
The CPU has three kinds of part: the control unit, the arithmetic logic unit, and a set of small, very fast storage locations called registers.
| Part | Job |
|---|---|
| CU control unit | Decodes instructions and sends control signals to manage the rest of the CPU and memory. |
| ALU arithmetic logic unit | Does calculations (+, −) and logical operations (AND, OR, comparisons). |
| PC program counter | Holds the address of the next instruction to fetch. |
| MAR memory address register | Holds the address in memory that is about to be read from or written to. |
| MDR memory data register | Holds the data or instruction just read from memory, or about to be written to it. |
| CIR current instruction register | Holds the instruction currently being decoded and executed. |
| ACC accumulator | Holds the result of calculations done by the ALU. |
Buses
Buses are sets of parallel wires that connect the CPU to memory:
- Address bus: carries an address from the MAR to memory. One direction only.
- Data bus: carries data and instructions between the CPU and memory. Both directions.
- Control bus: carries signals such as read, write, and clock pulses from the CU. Both directions.
The fetch-decode-execute cycle
Step through the cycle below. The memory holds a tiny program: LDA 0110 means "load the value stored at address 0110 into the accumulator". Watch the values move between registers.
What makes a CPU faster
| Factor | What it is | Why it helps |
|---|---|---|
| Clock speed | Number of clock cycles per second, in GHz | More clock cycles per second, so instructions are processed faster |
| Cores | Separate processing units inside one CPU | Several instructions can be processed at the same time |
| Cache | Very fast memory inside the CPU | Frequently used data and instructions are fetched without going to slower RAM |
Watch out. Doubling the cores does not always double the speed. Some programs cannot be split into parts that run at once, and cores have to coordinate.
Instruction sets and embedded systems
An instruction set is the list of all the machine code commands a CPU can understand and carry out, such as load, add, store, and jump.
An embedded system is a computer built into a larger device to do one dedicated job, such as the controller in a washing machine, a microwave, a car's engine management, or a heating thermostat. Embedded systems are small, cheap, and use little power, but they are hard to upgrade.
Key terms
- Von Neumann architecture
- A design where instructions and data share the same memory.
- Register
- A small, very fast storage location inside the CPU.
- Bus
- A set of parallel wires that carries addresses, data, or control signals.
- Cache
- Small, fast memory in the CPU that stores frequently used data and instructions.
- Embedded system
- A computer system built into a device to perform a dedicated function.
Check yourself
Which register holds the address of the next instruction?Show answer
The program counter (PC).
Describe what happens to the MAR and MDR during the fetch stage.Show answer
The address from the PC is copied into the MAR. The instruction at that address is read from memory along the data bus into the MDR.
Why does a larger cache improve performance?Show answer
More frequently used data and instructions can be kept in fast cache, so the CPU waits less for slower RAM.
Give two examples of embedded systems.Show answer
For example: a washing machine controller, a microwave, a smart thermostat, a car's anti-lock braking system.