The machine instruction cycle: Difference between revisions
Mr. MacKenty (talk | contribs) |
Mr. MacKenty (talk | contribs) No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
[[File:Fetch-execute-cycle.png|400px]] | [[File:Fetch-execute-cycle.png|400px]] | ||
<br /> | <br /> | ||
The | 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 === | === 1. Fetch === | ||
Line 44: | Line 21: | ||
=== 3. Execute === | === 3. Execute === | ||
The | 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 === | === 4. Store === | ||
Line 60: | Line 37: | ||
CIR (Current Instruction Register): Stores the current instruction being decoded and executed. | CIR (Current Instruction Register): Stores the current instruction being decoded and executed. | ||
ACC (Accumulator): Holds the result of calculations performed by the ALU. | 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). | The cycle then repeats, fetching the next instruction from memory as indicated by the Program Counter (PC). | ||
== Excellent simulations of the machine instruction cycle == | == Excellent simulations of the machine instruction cycle == |
Latest revision as of 11:18, 11 September 2024
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)