The Instruction Cycle (Machine Cycle)
The instruction cycle is the basic process by which a computer retrieves a program instruction from its memory, determines what actions the instruction requires, and carries out those actions. This cycle is repeated continuously by the CPU from boot-up to shut-down.
The Four Main Stages
Every instruction cycle consists of several key phases managed by the Control Unit.
- **1. Fetch:** The CPU retrieves the instruction from the memory address stored in the **Program Counter (PC)**. The instruction is placed into the **Instruction Register (IR)**.
- **2. Decode:** The Control Unit interprets the binary code in the IR. It identifies the operation to be performed and the operands required.
- **3. Execute:** The CPU performs the operation. This might involve the ALU for calculations, moving data between registers, or jumping to a different address.
- **4. Store (Write-back):** The result of the execution is written back to memory or a specific CPU register.
Key Registers Involved
| Register | Full Name | Role in the Cycle |
|---|---|---|
| PC | Program Counter | Holds the address of the next instruction. |
| MAR | Memory Address Register | Holds the address where data is read or written. |
| MDR | Memory Data Register | Holds the actual data being transferred to/from memory. |
| IR | Instruction Register | Holds the current instruction being decoded. |
| ACC | Accumulator | Stores intermediate ALU results. |
Timing and Clock Cycles
The speed at which the CPU moves through these cycles is determined by the system clock. One instruction might take one or several 'T-states' (clock pulses) to complete depending on its complexity.
Step 1: MAR <- PC
Step 2: MDR <- Memory[MAR]; PC <- PC + 1
Step 3: IR <- MDR
Step 4: Decode & Execute
Common Mistakes to Avoid
- Assuming every instruction takes exactly one clock cycle (CISC instructions often take many).
- Confusing the 'Program Counter' with the 'Instruction Register'.
- Forgetting that the PC increments *during* the fetch phase, not after execution.
- Ignoring the 'Interrupt' phase that occurs at the end of many cycles.
Advanced Concepts
- Micro-operations and RTL (Register Transfer Language)
- Wait States and Memory Latency
- Overlapping Fetch and Execute (Early Pipelining)
- Indirect Cycles (Fetching operand addresses)
- Instruction Prefetching
Practice Exercises
- Trace the register changes for a 'LOAD R1, 500' instruction.
- Explain what happens to the PC if the current instruction is a JUMP.
- Why do we need both MAR and MDR registers?
- Calculate the time taken for a cycle if the clock frequency is 2GHz and the instruction takes 4 cycles.
Conclusion
The Instruction Cycle is the heartbeat of computer architecture. By breaking complex tasks into these simple, repetitive steps, the CPU can execute billions of instructions per second with absolute precision.
Codecrown