Computer Architecture · Cambridge syllabus 3.1 · Lesson 3 of 5
Fetch–Decode–Execute Cycle
During fetch, the PC address is copied to MAR and memory is read into MDR. The instruction is copied to CIR and PC advances. The control unit decodes it, then the required operation is executed. Branch instructions can change the next address.
By the end, you can
- Explain how the address of the next instruction is held in the program counter.
- Explain how the address is transferred to the MAR.
- Explain how the instruction is fetched from memory.
- Explain the role of the MDR and CIR.
- Explain how the control unit decodes the instruction.
- Explain how the instruction is executed.
- Explain how the program counter is updated.
- Describe the complete fetch–decode–execute cycle.
Fetch
Running a program is one loop repeated for every instruction: fetch it from memory, decode what it means, execute it. The cycle then starts again, and it does not stop while the computer is on.
The fetch stage moves the next instruction from memory into the CPU in four steps. The address in the program counter is copied to the memory address register. That address goes out on the address bus and a read signal goes out on the control bus.
Memory returns the contents of that location on the data bus, and they arrive in the memory data register. The instruction is then copied from the MDR into the current instruction register, where the decoder can work on it.
The program counter is increased by one at this point, not at the end, so it is already pointing at the following instruction while the current one is still being carried out. This matters: a jump instruction executed later overwrites the program counter, and it must overwrite a value that has already been incremented.
Describing the fetch stage in an answer means naming the registers and the buses in order. Each step is a transfer between two named places, and the marks are for the transfers.
Worth remembering
- PC to MAR, address out on the address bus, read signal on the control bus.
- The instruction returns on the data bus into the MDR, then into the CIR.
- The PC is incremented during the fetch, before the instruction is executed.
Decode and execute
Decoding is the control unit working out what the instruction in the current instruction register means. An instruction has two parts: an opcode saying which operation to perform, and an operand giving the value to use or the address where it lives. The control unit interprets the opcode and generates the internal signals that will carry it out.
Executing is those signals doing their work, and what happens depends entirely on the instruction. An arithmetic instruction sends values to the ALU and leaves the answer in the accumulator. A load instruction fetches a value from memory into a register, which means another trip through the MAR and MDR. A store instruction sends a value the other way. A jump instruction writes a new address into the program counter.
The cycle then repeats with whatever the program counter now holds — the next instruction in sequence in the ordinary case, or somewhere else entirely if a jump was executed. Selection and iteration in a high-level language both come down to conditional jumps at this level.
So the whole cycle in order is: copy the PC into the MAR; fetch the instruction along the data bus into the MDR; copy it into the CIR; increment the PC; decode the opcode in the control unit; execute it, using the ALU and accumulator if there is a calculation; repeat.
Worth remembering
- An instruction has an opcode (what to do) and an operand (what to do it to).
- The control unit decodes the opcode into signals; execution uses the ALU and registers.
- A jump executes by writing a new address into the program counter.
Worked example
For LOAD 4, the fetched instruction is decoded; memory location 4 is read and its value is placed in the accumulator.
Practice
Warm-up · not marked
Check your understanding
Answer in your own words, then compare with the worked answer. Nothing here is saved or scored.
Worked answer
It must point to the next instruction, normally the following address unless control flow changes it.
Check your method, units and explanation against it.
Marked practice
Set 1 of 4 · easiest first · Checked as you go, with the worked answer. Sign in or create a free account to save your progress.