Edexcel International Advanced Level Computer Science, point 1.1.5
Definition
The fetch-decode-execute (FDE) cycle is the repeated process by which the CPU gets an instruction from memory, works out what it means, and carries it out. The CPU does this billions of times a second.
Function and why needed
It is how every program runs. Without the cycle, instructions stored in memory would never be turned into actions.
a. The stages
| Stage | What happens |
|---|---|
| Fetch | The instruction is copied from memory into the CPU, and the PC is moved on to the next instruction |
| Decode | The control unit works out what the instruction means (which operation, and which operands) |
| Execute | The operation is carried out: for example, the ALU calculates, data is loaded or stored, or the PC is changed by a jump |
b. The role of components
| Component | Role in the cycle |
|---|---|
| PC | Holds the address of the next instruction |
| MAR | Holds the address sent to memory |
| MBR | Holds the instruction or data returned from memory |
| CIR | Holds the instruction being decoded |
| Control unit | Decodes and sends control signals |
| ALU | Does the calculation or comparison |
| ACC / registers | Hold values and results |
| Address bus | Carries the address to memory |
| Data bus | Carries the instruction or data back |
| Control bus | Carries the read and write signals |
| Clock | Times each step |
c. Read and write control signals
Memory must be told what to do with the address on the address bus:
- A read signal on the control bus tells memory to put the contents of that location on the data bus. It's used when fetching an instruction and when loading data.
- A write signal tells memory to store the value on the data bus in that location. It's used when storing data.
Register transfer notation (RTN)
RTN shows exactly how data moves between registers:
- Square brackets [ ] mean the contents of a register.
- The arrow ← means "is loaded with". The register being loaded is on the left.
So MAR ← [PC] means "the contents of the PC are loaded into the MAR".
RTN is used for moves between registers. Reading from or writing to memory is described in words (along with the read or write signal).
The fetch stage
| Step | RTN or action | What happens |
|---|---|---|
| 1 | MAR ← [PC] | The address of the next instruction is copied into the MAR |
| 2 | Address bus, read signal | The address is sent to memory, and the CU sends a read signal on the control bus |
| 3 | Data bus to the MBR | Memory sends the contents of that address back to the MBR |
| 4 | CIR ← [MBR] | The instruction is copied into the CIR |
| 5 | PC ← [PC] + 1 | The PC is incremented, so it points to the next instruction |
(The PC is often incremented at the same time as the memory is being read, but either way it is ready, pointing to the next instruction, before the following fetch.)
The decode stage
The control unit decodes the contents of the CIR. The instruction is split into an opcode (what to do, such as load) and an operand (a value, or the address of the data).
The execute stage: some examples
The details depend on the instruction.
Load the value at address 50 into the accumulator:
| Step | RTN or action | What happens |
|---|---|---|
| 1 | MAR ← [CIR operand] | The address 50 is copied into the MAR |
| 2 | Read signal | The contents of address 50 come back on the data bus into the MBR |
| 3 | ACC ← [MBR] | The data is copied into the accumulator |
Store the accumulator at address 60:
| Step | RTN or action | What happens |
|---|---|---|
| 1 | MAR ← [CIR operand] | The address 60 is copied into the MAR |
| 2 | MBR ← [ACC] | The data to be stored is copied into the MBR |
| 3 | Write signal | The contents of the MBR are stored at address 60 |
Jump to address 20:
| Step | RTN | What happens |
|---|---|---|
| 1 | PC ← [CIR operand] | The PC now holds 20, so the next fetch is from address 20 |
Add (when the value to add is already in the MBR):
| Step | RTN | What happens |
|---|---|---|
| 1 | ACC ← [ACC] + [MBR] | The ALU adds the two values, and the result goes into the accumulator |
Worked example
Task: the PC holds 100. Memory location 100 holds the instruction to load the value at address 500 into the accumulator. Memory location 500 holds the value 42. Show the registers after each step of the cycle.
| Step | RTN or action | PC | MAR | MBR | CIR | ACC |
|---|---|---|---|---|---|---|
| Start | 100 | |||||
| Fetch 1 | MAR ← [PC] | 100 | 100 | |||
| Fetch 2 | Read signal; instruction to the MBR | 100 | 100 | LOAD 500 | ||
| Fetch 3 | CIR ← [MBR] | 100 | 100 | LOAD 500 | LOAD 500 | |
| Fetch 4 | PC ← [PC] + 1 | 101 | 100 | LOAD 500 | LOAD 500 | |
| Decode | CU decodes [CIR] | 101 | 100 | LOAD 500 | LOAD 500 | |
| Execute 1 | MAR ← [CIR operand] | 101 | 500 | LOAD 500 | LOAD 500 | |
| Execute 2 | Read signal; data to the MBR | 101 | 500 | 42 | LOAD 500 | |
| Execute 3 | ACC ← [MBR] | 101 | 500 | 42 | LOAD 500 | 42 |
The PC is 101, ready for the next fetch.
Exam tip: write RTN with the destination on the left and square brackets for contents, such as MAR ← [PC]. Remember the PC is incremented during the fetch, so it points to the next instruction. Show the read signal when memory is read and the write signal when it is written. You can be asked to complete a diagram of the data transfers, so practise drawing the path PC, MAR, memory, MBR, CIR.
Check yourself
Name the three stages of the FDE cycle
Fetch, decode and execute.
What does MAR ← [PC] mean?
The contents of the program counter are copied into the memory address register.
When is the PC incremented, and why?
During the fetch stage, so that it points to the next instruction ready for the following cycle.
When is the write signal used?
When data is being stored into memory, such as during execution of a store instruction.
What happens to the PC when a jump instruction is executed?
It is loaded with the jump address from the instruction's operand, so the next fetch is from that address.