The fetch-decode-execute cycle

The fetch-decode-execute cycle

Fetch-Decode-Execute Cycle

  • The primary function of the central processing unit (CPU) can be summarised in three steps, collectively known as the fetch-decode-execute cycle.

Fetch

  • The fetch stage involves the CPU retrieving an instruction from the computer’s memory.
  • The address of the required instruction is held in the Program Counter (PC). This is a register in the CPU that holds memory addresses.
  • The instruction is fetched by sending a signal from the CPU to the memory along the address bus.
  • The address bus is a one-way communication line from the CPU to the memory.
  • The instruction is then sent back to the CPU along the data bus. This is a two-way communication line between the CPU and the memory.

Decode

  • Once the instruction has been fetched, the CPU enters the decode stage.
  • The instruction is passed to a special register called the Instruction Register (IR) and a Control Unit inside the CPU decodes it.
  • Decoding is the process of transforming the instruction into a format that can be understood by the CPU.

Execute

  • In the execute stage, the decoded instruction is carried out by the CPU.
  • Depending on the instruction, this could involve arithmetic or logical operations performed by the Arithmetic Logic Unit (ALU), or movement of data from one register to another.
  • The process can also involve writing data to memory or outputting it to a device.
  • Once an instruction has been executed, the cycle starts again.

Instruction Cycle and CPU Clock

  • The duration of the fetch-decode-execute cycle is synchronised with the CPU clock.
  • Each cycle of the CPU clock allows for one fetch-decode-execute cycle, so the clock speed effectively determines how many instructions can be executed per second.
  • The CPU clock speed is measured in Hertz (Hz). 1 Hz means one cycle per second. Modern CPUs typically have clock speeds measured in gigahertz (GHz), which equates to billions of cycles per second.

Pipelining

  • Some modern CPUs implement a concept called pipelining.
  • Pipelining is where different stages of different instructions are processed at the same time.
  • For instance, while one instruction is in the execute stage, another could be in the decode stage and a third in the fetch stage.
  • Pipelining can significantly increase the speed of processing in a CPU.