Resources | Subject Notes | Computer Science
The fetch–decode–execute cycle is the fundamental process by which a central processing unit (CPU) executes instructions. It's a repetitive cycle that continues as long as the computer is running. Each cycle involves retrieving an instruction from memory, interpreting it, and then carrying out the specified operation.
The fetch–decode–execute cycle consists of three main stages:
In the fetch stage, the CPU retrieves the next instruction from main memory (RAM). The address of the next instruction is stored in a special register called the Program Counter (PC). The PC is incremented after each instruction is fetched, pointing to the next instruction in sequence. The fetched instruction is then loaded into the Instruction Register (IR).
Step | Description |
---|---|
1 | The address in the Program Counter (PC) is used to access the memory location containing the next instruction. |
2 | The instruction at that memory location is fetched and transferred to the Instruction Register (IR). |
3 | The Program Counter (PC) is incremented to point to the next instruction in memory. |
The decoded stage involves interpreting the instruction in the Instruction Register (IR). The instruction is broken down into its component parts, identifying the operation to be performed and the operands (data) required. This is done by the Control Unit (CU), which examines the instruction's opcode.
The opcode specifies the operation (e.g., addition, subtraction, data transfer). The operands specify the data or memory locations that the operation will act upon.
Step | Description |
---|---|
1 | The instruction in the Instruction Register (IR) is examined by the Control Unit (CU). |
2 | The opcode of the instruction is identified. |
3 | The operands required for the instruction are determined. |
In the execute stage, the CPU carries out the operation specified by the decoded instruction. This might involve performing arithmetic calculations using the Arithmetic Logic Unit (ALU), transferring data between registers and memory, or controlling other parts of the computer.
The ALU performs the actual operation on the operands. The results of the operation are then stored in registers or written back to memory.
Step | Description |
---|---|
1 | The operation specified by the decoded instruction is performed. |
2 | The Arithmetic Logic Unit (ALU) performs the required calculation or operation. |
3 | The results of the operation are stored in registers or written back to memory. |
After the execute stage, the cycle repeats, starting with the fetch stage. This continuous cycle allows the CPU to execute a sequence of instructions, forming a program.
The fetch–decode–execute cycle is the fundamental basis of how computers operate. It allows for the execution of complex programs by breaking them down into a series of simple, repeatable steps.