Fetch-decode-execute cycle

The main job of the CPU is to execute programs using the fetch-decode-execute cycle (also known as the instruction cycle). This cycle begins as soon as you turn on a computer.

To execute a program, the program code is copied from secondary storage into the main memory. The CPU's program counter is set to the memory location where the first instruction in the program has been stored, and execution begins. The program is now running.

In a program, each machine code instruction takes up a slot in the main memory. These slots (or memory locations) each have a unique memory address. The program counter stores the address of each instruction and tells the CPU in what order they should be carried out.

When a program is being executed, the CPU performs the fetch-decode-execute cycle, which repeats over and over again until reaching the STOP instruction.

The Decode-Execute-Fetch cycle between the registers, control unit, ALU and RAM

Summary of the fetch-decode-execute cycle

  1. The processor checks the program counter to see which instruction to run next.
  2. The program counter gives an address value in the memory of where the next instruction is.
  3. The processor fetches the instruction value from this memory location.
  4. Once the instruction has been fetched, it needs to be decoded and executed. For example, this could involve taking one value, putting it into the ALU, then taking a different value from a register and adding the two together.
  5. Once this is complete, the processor goes back to the program counter to find the next instruction.
  6. This cycle is repeated until the program ends.
Move on to Test
next