The CPU executes the instructions regarding a program stored in the memory. There’s one general rule applied to all these instructions being carried out in the processors. The execution definition is outlined by a cycle of instructions conducted in the particular execution. This cycle, better known as the instruction cycle, has three stages – fetch, decode and execute.
What is the Instruction Cycle?
The execution instructions define the instruction cycle. This is the thorough methodology computer processors use for executing a given instruction. Many times processors can be compared to combustion engines. Both follow a process continuously being carried out to fetch the desired outcome. Every processor shows a three-step instruction cycle. These three steps of the instruction execution cycle are,
1.Fetch:
The processor copies the instruction data captured from the RAM.
2. Decode:
Decoded captured data is transferred to the unit for execution.
3. Execute:
Instruction is finally executed. The result is then registered in the processor or RAM (memory address).
First step: Fetch (instruction cycle)
According to the execution instruction definition, the instruction cycle’s first step is to capture or fetch the instruction. This instruction in the fetch stage is captured from RAM. This memory is assigned to the processor through various units and registers; they are:
- Program counter:
It works by pointing towards the next memory line, where the next instruction for the processor is stored.
- Register (memory address): Responsible for copying PC content and sending it to the RAM. This is done through the CPU’s address pins.
- Register (memory data):
It takes the responsibility of copying the memory address to the internal register.
- Register (instruction):
It has involvement in the last step of the fetch phase. It is where the instruction is written. The control unit from here copies the content for carrying out the instruction cycle.
How does the control unit work?
As discussed earlier, the control unit plays an important part and is present in a processor. The tasks that it performs are,
- The control unit is responsible for controlling both internal and external movements of the data in the processor. Also, it is responsible for controlling the movement of the data in various subunits involved
- Various units of the capture stage of an instruction cycle are considered part of the hardware. This hardware is called a control unit or a processor’s front-end
- It is responsible for interpreting various instructions and sending them to the execution units
- Communicate that data for instruction to the various ALUs and execution units at work
- It is the part of the processor that captures and decodes the instruction for execution. Also, it is responsible for writing results on the registers and even in the respective addresses of the RAM
Second step: Decode (instruction cycle)
There are various instructions, and we can never be sure which instruction belongs to which execution unit. Decoding sorts this out. A decoder is responsible for taking in the instruction and decoding it to assign the respective execution unit to complete the execution instruction cycle.
The easiest example of how an instruction works is visualising them as trains that keep circulating through a complex railway network. The control unit here acts as the station at the terminal and, therefore, it is held in charge of being the execution unit to solve the given instruction.
Third step: Execute (instruction cycle)
The last stage of the execute instruction definition is to execute. It involves executing the given instruction that was fetched at the first stage. No two instructions ever get resolved in the same manner because their ways of utilising the hardware depend on their functions. There are four types of instructions that are generally present,
Bit movement instructions:
This instruction involves the manipulation of the bits’ order. These bits contain the data.
Arithmetic instructions:
These are the instructions that involve logical as well as mathematical operations. They are most often solved in arithmetic logical units (ALUs)
Jump instructions:
The code in this instruction is used recursively because the value for the next program counter is changed.
Instructions to memory:
These instructions involve the processor writing as well as reading the information from the memory of the system.
On completing the cycle, that is, the instruction being executed, a new instruction gets fetched, and the cycle continues.
Conclusion:
The processor in a computer is responsible for the beginning of the instruction cycle and the forthcoming steps of the instruction execution cycle. The first step for the processor is to check the next instruction to run in the program counter.
The program counter now gives the address value for the next instruction in the memory. The value for instruction is fetched out of this given location within the memory; after being fetched just according to the execution instruction definition, decoding and executing follow suit.
After this instruction is executed, the processor again turns to the program counter. It gets a new instruction. This way, the instruction cycle keeps repeating itself unless the instruction for STOP.
Also check: