Every instruction goes through the same three stages: fetch, decode and execute. This lesson follows one instruction step by step. You see which register is filled at each step, which bus carries what, and what the control unit and the ALU do.
about 25 min1 simulation1 practice question
Lesson 2 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
A cycle that never stops
A cook follows a recipe one line at a time. Read the next line. Understand it. Do it. Then read the next line. The CPU works the same way, millions of times each second. It is called the fetch-decode-execute (FDE) cycle.
A loop of three boxes joined by arrows: Fetch, then Decode, then Execute, and back to Fetch. Under Fetch: PC to MAR, address bus, data bus to MDR, MDR to CIR, PC plus 1. Under Decode: the control unit decodes the instruction in the CIR. Under Execute: the instruction is carried out, the ALU calculates and the result goes to the ACC.
The picture shows the cycle as a loop of three stages. The steps inside each stage are listed below.
Fetch
The instruction is copied from RAM into the CPU.
The address in the PC is copied to the MAR.
The address in the MAR is sent along the address bus to RAM. The control unit sends a read signal along the control bus.
The instruction at that address is sent along the data bus to the MDR.
The instruction in the MDR is copied to the CIR.
The PC is incremented by 1, so it holds the address of the next instruction.
Decode
The control unit decodes the instruction in the CIR. It works out what the instruction means and what it needs, such as an address of some data.
Execute
The instruction is carried out. The control unit sends signals to the parts that are needed.
To load data, its address goes to the MAR, and the data comes back along the data bus to the MDR. Then it goes into the ACC.
To calculate, the ALU does the work and the result goes into the ACC.
To store a result, the address goes to the MAR and the value goes to the MDR. Then it is written to RAM.
Then the cycle starts again with the next instruction.
One instruction, traced
The program from the last lesson starts at address 10. At the start the PC holds 10. Here is the first cycle, for LOAD 20.
Fetch. MAR gets 10. The instruction LOAD 20 comes to the MDR, then to the CIR. The PC becomes 11.
Decode. The CU finds that it must load the value at address 20.
Execute. MAR gets 20. The value at address 20, which is 7, comes to the MDR. It is copied to the ACC.
Notice that the MAR held two different addresses in one cycle. First it held the address of the instruction. Then it held the address of the data.
Practise with new numbers
Try it in Python
The program runs the whole tiny program through the cycle. It uses a variable for each register, and prints the registers after each fetch and each execute.
Common mistakes
Incrementing the PC at the wrong time. The PC goes up during the fetch stage, before the instruction is executed.
Leaving out the buses. An exam answer should say which bus carries the address and which carries the instruction.
Saying the ALU decodes the instruction. Decoding is the job of the control unit.
Forgetting the MDR. An instruction does not go straight from RAM to the CIR. It goes through the MDR.
Remember these
Fetch: PC to MAR, address bus, data bus to MDR, MDR to CIR, PC plus 1.
Decode: the CU decodes the instruction in the CIR.
Execute: the instruction is carried out. The ALU does any calculation and the result goes to the ACC.
The MAR always holds the address that is about to be used, of an instruction or of data.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Which register's contents are copied to the MAR at the start of a fetch?
Which bus carries the instruction from RAM to the CPU?
The PC holds 26 at the start of a fetch. What does it hold at the end of the fetch?
Which part of the CPU decodes the instruction in the CIR?
During one cycle the MAR holds 14 and then 31. Explain why.