The machine instruction cycle
The machine instruction cycle describes the order that instructions are processed in a computer.
The machine instruction cycle is the process a CPU follows to execute instructions stored in memory. It consists of four main stages: Fetch, Decode, Execute, and Store. Below is a breakdown of the cycle, along with the roles of key components such as the Control Unit (CU), Arithmetic Logic Unit (ALU), and various registers.
1. Fetch[edit]
The Control Unit (CU) initiates the fetch stage by using the Program Counter (PC) to store the address of the next instruction to be executed. This address is sent to the Memory Address Register (MAR), which holds the address of the required instruction in memory.
- The CU signals the memory to retrieve the instruction at the address in the MAR.
- The retrieved instruction is temporarily stored in the Memory Data Register (MDR).
- The instruction is then transferred to the Current Instruction Register (CIR) for decoding.
- The PC is incremented to point to the address of the next instruction in RAM.
2. Decode[edit]
Once the instruction is in the CIR, the Control Unit (CU) decodes it to determine what operation needs to be performed. The decoded instruction identifies whether data needs to be retrieved, stored, or manipulated.
3. Execute[edit]
The Arithmetic Logic Unit (ALU) performs the necessary calculations or logical operations, depending on the instruction. For example, if the instruction involves an arithmetic operation (addition, subtraction, etc.), the ALU processes the data.
- Data required for the operation may be fetched from memory or registers.
- The Accumulator (ACC) stores the result of operations carried out by the ALU, such as the sum of two numbers.
4. Store[edit]
After execution, the result in the ACC may need to be stored back into memory or passed to another register for further operations. If the instruction involves interacting with external devices, the Interrupt Register (IR) may be involved, handling requests from I/O devices to ensure they are serviced when required.
During the entire instruction cycle, the Control Unit (CU) coordinates the movement of data between the registers and manages the flow of control within the CPU.
Registers' Summary[edit]
PC (Program Counter): Stores the address of the next instruction to be fetched. MAR (Memory Address Register): Stores the memory address of the data or instruction to be fetched or stored. MDR (Memory Data Register): Holds the data fetched from or to be written to memory. CIR (Current Instruction Register): Stores the current instruction being decoded and executed. ACC (Accumulator): Holds the result of calculations performed by the ALU.
The cycle then repeats, fetching the next instruction from memory as indicated by the Program Counter (PC).
Excellent simulations of the machine instruction cycle[edit]
- It can be helpful to imagine there is a little mailman inside your computer! Click here to learn more about this technique
- Click here for a great simulation!
- This is also very good simulation (little man simulation)