The Journey of Instructions in Computer Systems?

·

2 min read

The computer is all about instructions at the end of the day. We usually instruct a computer using a high-level language like Java, C, and C++ which ultimately gets compiled into binary 1s and 0s with the help of the compilers. The instruction size depends upon the architecture selected. It could be 4 bits, 8 bits, 16 bits, or 64 bits. As per the architecture, the compiler generates the instruction.

Have you ever wondered how these instructions are executed on the computer? Well, let's talk about that today.

What is an instruction?

An instruction is a sequence of bits that instructs a computer to perform a specified operation over a specified operand. These instructions are stored in the main memory.

Instruction Cycle

Instruction fetch: The instruction are stored in the main memory. The CPU fetches the instruction from the main memory. The instruction is stored in the Instruction Register in the CPU. The Program Counter Register stores the address of the next instruction to be fetched. The moment an instruction is fetched the value of the Program Counter is incremented.

Instruction Decode: The instruction fetched from the main memory and stored in the instruction register is decoded to discover the operation that needs to be performed on the operand whose address is also decoded.

Effective address calculation*:* Since the operation needs to be performed on the operand and its address has already been received through the decoding process of instruction.

Operand fetch: Once the effective address is calculated, the CPU fetches the data from the main memory through the data bus.

Instruction execution: The Arithmetic and Logical unit performs the operation and the result is stored in the special purpose register called an accumulator.

Write back: The result of the instruction execution is written back to a register or memory location, as appropriate. This process is called writing back.

The instruction cycle is repeated for each instruction in the program until the program is complete or an error occurs. The phases of the instruction cycle are essential to understanding how a computer executes instructions and performs computations.

It is not mandatory for each instruction to go through all the phases in the cycle. Instruction fetch, Instruction decode, and Instruction execution are mandatory.