1.1.1 Architecture of the CPU
Every computer has a central processing unit (CPU). It is often called the "brain" of the computer, but it does not think. It follows instructions, one after another, very quickly.
A program is a list of instructions stored in main memory (RAM). The CPU cannot run them where they are. It must bring them into the CPU one at a time. It does this over and over, millions or billions of times a second, using the fetch-execute cycle.
The fetch-execute cycle
The fetch-execute cycle is the process the CPU repeats for every instruction. It has three stages.
- 1.Fetch. The CPU gets the next instruction from main memory. The Program Counter tells it where that instruction is.
- 2.Decode. The control unit works out what the instruction means and what has to be done.
- 3.Execute. The instruction is carried out. For example, the ALU adds two numbers, or a value is stored in memory.
Main components of the CPU
Arithmetic logic unit (ALU)
When a program adds two numbers or checks whether one number is bigger than another, the ALU does the work.
Control unit (CU)
Cache
Getting something from RAM is slower than getting it from cache. If the CPU finds what it needs in the cache, it does not have to wait for RAM. This makes the computer faster.
Registers
Registers are faster than cache, and cache is faster than RAM. You must know four registers.
Von Neumann architecture
Almost all modern general-purpose computers are built this way. It means a computer can run any program that is loaded into memory, not just one fixed program.
The Von Neumann design uses four registers. Each has one job.
| Register | What it is for | Holds |
|---|---|---|
| Program Counter (PC) | Keeps track of where the next instruction is in memory | An address |
| Memory Address Register (MAR) | Holds the address of the memory location that is about to be read from or written to | An address |
| Memory Data Register (MDR) | Holds the data (or instruction) that has just been fetched from memory, or is about to be written to memory | Data |
| Accumulator (ACC) | Holds the result of calculations done by the ALU | Data |
Data and addresses
Memory is like a long row of numbered boxes. Each box is a memory location. Each location has two things.
- •An address: the number of the box. It says *where* the box is.
- •The data inside it: the value stored in the box. It says *what* is stored.
- The address is 40.
- The data is 17.
To read the value, the MAR holds the address 40. The MDR then holds the data 17 that was fetched from that address.
Do not mix these up. The number 40 and the number 17 might both be stored in registers, but they mean different things. One says where to look. The other is what was found.
Putting it together
A program has the instruction "add 5 to the running total".
- •The Program Counter points to where this instruction is stored.
- •The instruction is fetched from memory and decoded by the control unit.
- •It is executed: the ALU does the addition.
- •The result is held in the accumulator.
- •Data that is used often may be found in the cache, which saves a trip to RAM.
Exam technique
- •State and give: one short fact per mark. "State the purpose of the ALU."
- •Describe: say what happens at each stage, in order. For the fetch-execute cycle, name all three stages and say what happens in each.
- •Explain: give a reason. "Cache makes the CPU faster because it stores frequently used data close to the CPU, so the CPU does not wait for RAM."
- •For registers, always say what it holds and whether that is an address or data.
- •Use the exact name: "fetch-execute cycle". Do not write about wires or buses between the parts. It is not needed.