The Fetch, Decode, and Execute Cycle
- The Fetch Decode Execute cycle is the basic set of steps the CPU repeats to run any instruction.
- This process is synchronised by the clock, the component that keeps everything ticking in time.
What is the Clock?
- The clock is a tiny circuit that sends out regular electrical pulses.
- Each pulse = one clock cycle.
- The CPU uses these pulses to time its operations, every stage of the FDE cycle happens in sync with the clock.
- Clock speed is measured in Hertz (Hz) e.g. 3GHz = 3 billion cycles per second.
“More clock speed = always faster.”
However, this is not always the case: other factors like cache, instruction type, and core architecture also matter.
NoteFaster clock = more instructions processed per second, but also more heat and power usage.
AnalogyThe clock is like a metronome in an orchestra, it keeps everything moving at the same pace, beat by beat.
Overview of the Fetch, Decode, and Execute Cycle
- The fetch, decode, and execute cycle is the fundamental process by which a CPU executes instructions.
- It consists of three main phases:
- Fetch: Retrieve the instruction from memory.
- Decode: Interpret the instruction.
- Execute: Perform the operation specified by the instruction.
The speed and efficiency of a CPU are largely determined by how quickly it can complete this cycle.
Fetch Phase: Retrieving Instructions
- Program Counter (PC): Holds the address of the next instruction to be executed.
- Memory Address Register (MAR): Receives the address from the PC.
- Control Unit: sends a signal on the control bus to "read".
- The address bus carries the address from the MAR, the control bus carries the signal to "read" and the data or instruction at the specified location is then returned from memory to the CPU on the data bus.
- Memory Data Register (MDR): Temporarily holds the fetched instruction.
- Instruction Register (IR): Stores the instruction for decoding.
- This whole process is timed by the clock, fetch happens on one or more cycles.
The address bus carries the memory address from the MAR to the memory, while the data bus transfers the instruction from memory to the MDR.
CPU Instruction Set
The instruction set is the collection of basic machine-level commands that a CPU is designed to understand and execute. such as load, store, add, compare, and jump.
It forms the CPU’s vocabulary and defines what operations it can perform.