Computer Architecture
What is inside the processor, and the cycle it repeats billions of times a second.
WATCH IT EXPLAINED
EXPLORE IT IN 3D
Inside the computer
A real motherboard is on the bench. Find its parts, lift the lid off the CPU, run a program one fetch, decode and execute at a time — then make it faster.
What the CPU does
The CPU runs a program by fetching, decoding and executing instructions, billions of times every second.
The central processing unit (CPU) processes the instructions and data that are input into the computer, so that the result can be output.
It runs a program by repeating one cycle:
- Fetch an instruction from memory.
- Decode it (work out what it means).
- Execute it (carry it out).
It repeats this cycle billions of times every second.
A microprocessor is a type of integrated circuit on a single chip. An embedded system, such as the controller in a washing machine, contains a microprocessor.
Von Neumann architecture
In a Von Neumann computer, instructions and data share one memory, and the CPU fetches them one at a time.
In a Von Neumann computer, the program's instructions and its data are stored together in the same main memory (RAM). The CPU fetches them from there, one at a time.
Inside the CPU there are:
- two units: the arithmetic logic unit (ALU) and the control unit (CU)
- a set of registers (small stores inside the CPU)
Three buses (groups of wires) connect the CPU to memory: the address bus, the data bus and the control bus.
Remember:An instruction and a number are both just binary in memory. So the CPU treats whatever the program counter points at as the next instruction.
The ALU and the control unit
The ALU does the calculations; the control unit decodes each instruction and tells the other parts what to do.
The arithmetic logic unit (ALU) does the calculating:
- arithmetic, such as addition and subtraction
- logic operations, such as
AND,ORand comparisons
The control unit (CU) is like the conductor of an orchestra:
- It decodes each instruction.
- It sends control signals to the other components, along the control bus. So data moves to the right place at the right time.
- It uses the clock to keep every step in time.
Watch out:Neither unit stores the program. The program is held in memory.
The registers
Registers are small stores inside the CPU, and each register has one job.
A register is a component inside the CPU that stores data, an address or an instruction for a short time.
| Register | What it holds | Kind |
|---|---|---|
| Program counter (PC) | the address of the NEXT instruction to be fetched | address |
| Memory address register (MAR) | the address of the memory location about to be read from or written to | address |
| Memory data register (MDR) | the data or instruction just read from memory, or the data about to be written to it | data or instruction |
| Current instruction register (CIR) | the instruction currently being decoded and executed | instruction |
| Accumulator (ACC) | the value being worked on, and the results of the ALU's calculations | data |
Remember:The PC and the MAR hold addresses. The MDR, CIR and ACC hold data or instructions.
The three buses
Three buses link the CPU and memory, and only the address bus is one-way.
A bus transmits data, addresses or signals between the components of a computer.
| Bus | What it carries | Direction |
|---|---|---|
| address bus | addresses, from the MAR to memory | one-way (unidirectional) |
| data bus | data and instructions, between the CPU and memory | both ways (bidirectional) |
| control bus | control signals, such as memory read, memory write and the clock | both ways |
Example:In the figure, compare reading RAM[5] with writing to RAM[7]. Only the data bus changes direction.
Fetch
To fetch, the CPU sends the PC's address to memory, and the instruction comes back through the MDR into the CIR.
Every instruction is fetched in the same five steps:
PC → MAR: the address in the PC is copied into the MAR. It is the address of the next instruction.- The address goes along the address bus to memory. At the same time, the control unit sends a READ signal along the control bus.
data bus → MDR: the instruction stored at that address is sent along the data bus into the MDR.MDR → CIR: the instruction is copied from the MDR into the CIR.PC ← PC + 1: the PC is incremented by 1, so it holds the address of the next instruction.
Watch out:Step 5 can happen at any point after step 1, once the PC's value has been copied into the MAR. That is why books put it in different places.
Decode and execute
Decode works out what the instruction means; execute carries it out; then the next fetch begins.
Decode. The control unit works out what the instruction in the CIR means:
- the opcode: which operation to do
- the operand: what it acts on (here, an address)
Execute. The control unit sends the signals that carry it out. For example:
| Instruction | What happens |
|---|---|
LDA 5 | copies the value at address 5 into the ACC, through the MAR and the MDR |
ADD 6 | fetches the value at address 6, and the ALU adds it to the ACC |
STA 7 | puts the ACC's value into the MDR and writes it to address 7 |
Then the cycle starts again with the next fetch.
FETCH (the same five steps every time)
PC → MAR, address bus,
data bus → MDR, MDR → CIR,
PC ← PC + 1
DECODE (the CU reads the CIR)
ADD 6 is opcode ADD, operand 6
(the operand is an address)
EXECUTE (different for each instruction)
LDA 5 MAR ← 5, read, MDR ← 2,
ACC ← MDR
ADD 6 MAR ← 6, read, MDR ← 7,
ALU: ACC ← ACC + MDR = 9
STA 7 MAR ← 7, MDR ← ACC,
write → RAM[7] = 9The instruction set
A CPU can only run the commands in its own instruction set, and those commands are binary machine code.
An instruction set is the list of all the commands a CPU can process. Those commands are machine code (binary).
Each instruction usually has two parts:
| Part | What it says | Example |
|---|---|---|
| opcode | what to do | ADD |
| operand | what data or address to use | 6 |
The control unit uses the instruction set to decode each instruction.
Watch out:A CPU can only process the commands in its own instruction set. A code that is not in the set cannot be run.
The figure uses an invented set of four instructions.
An invented instruction set:
opcode mnemonic
0000 HLT
0001 LDA
0010 ADD
0011 STA
address instruction machine code
0 LDA 5 0001 0101
1 ADD 6 0010 0110
2 STA 7 0011 0111
3 HLT 0000 0000Clock speed
The clock sets how many fetch–decode–execute cycles happen each second; a faster clock runs more instructions per second.
The CPU's clock sends out a steady stream of pulses, like a drummer keeping the beat. It controls how many fetch–decode–execute cycles are performed each second.
Clock speed is the number of pulses (cycles) per second. It is measured in hertz (Hz).
Example:3.5 GHz is 3 500 000 000 cycles a second.
A higher clock speed means more cycles per second. So more instructions are carried out each second, and performance improves.
Cores
More cores can work at the same time, but only on work that can be split between them.
A core is a processing unit inside the CPU that can fetch, decode and execute instructions. A CPU can have several.
Think of cashiers in a shop. More cashiers serve more customers at once. But one customer's payment cannot be split between two cashiers.
More cores can process more instructions at the same time, but only when the work can be split between them. Some parts of a job cannot be split at all.
Watch out:So doubling the number of cores does not always double the performance.
Example:In the figure, 4 cores take 1.75 s, not 1 s, because 25% of the job cannot be split.
Cache
Cache is very fast memory in the CPU that keeps what the CPU uses most, so it waits less.
Cache is very fast memory inside the CPU. It stores frequently used instructions and data. It is like keeping your most-used books on your desk, not in the library.
When the CPU needs something:
- It checks the cache first.
- If it is there, the CPU does not wait for it to come from RAM, which is much slower.
A larger cache holds more of what the program keeps using. So more requests are found in the cache, the CPU waits less, and performance improves.
Example:In the figure, 4 slots instead of 2 turn 3 hits into 8.
Embedded systems
An embedded system is a computer inside a larger device, built to do one job.
An embedded system is a computer built into a larger device to perform a dedicated function (one job). It is found, for example, in:
- domestic appliances
- cars
- security systems
- lighting systems
- vending machines
| Embedded system | General-purpose computer | |
|---|---|---|
| Example | the controller in a vending machine | a PC or laptop |
| Used for | one dedicated function | many different functions |
Embedded systems are usually small, cheap to manufacture and need little power. They contain a microprocessor and run firmware: a program stored permanently in the device, which the user usually cannot change.
- Click the stages below in the order they happen.
KEY TERMS
CHECK YOURSELF
1.Which register holds the address of the NEXT instruction?
2.In the fetch stage, what is copied into the MAR?
3.Why does a larger cache make a computer faster?
4.During the fetch, where is the instruction copied to after it arrives in the MDR?
5.Which bus is one-way (unidirectional)?
6.Which of these is an embedded system?