The microprocessor (also known as Central Processing Unit (CPU)) can be defined simply as a calculation machine. It executes predefined operations called instructions. The steps the CPU performs in order to execute an instruction is called an instruction cycle (also known as fetch-execute cycle or fetch-decode-execute cycle). Understanding the instruction cycle is a great starting point for getting familiar with the overall functionality of the CPU. The instruction cycle can be viewed as an abstract model of the CPU. Most of the hardware units part of the CPU are there to accommodate the instruction cycle.
The instruction cycle can generally be divided into three distinct phases:
The Fetch Phase
This is the first phase of the instruction cycle. The program counter’s value is used for addressing (accessing) a specific cell from the program memory. This memory cell contains the instruction that have to be executed by the CPU at the end of the instruction cycle. The retrieval from program memory and the placement of this instruction into the instruction register (IR) is referred to as fetching. At the end of the current fetch phase the program counter’s value is increased to point to the next memory address.
The Decode Phase
In this phase the control unit of the CPU performs few actions based on the value of the instruction register (the fetched value):
- Decode the instruction – the opcode of the instruction defines what type of instruction it is (e.g data processing, memory access etc.).
- Fetch the operands – based on the opcode and additional information contained in the instruction format, the control unit determines what type of operands are needed and where they should be fetched from.
The Execute Phase
The execution is the last phase of the instruction cycle. Here the actual operation specified by the fetched instruction is performed. If it is a data processing instruction then the operands are passed through the ALU and/or other data manipulation units if available for processing. At the end of the execute phase, the result of the executed instruction is stored in either the data memory or a CPU register (depending on the architecture and the instruction).