Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Program execution in CPU
One may be amazed how the CPU is programmed. A special register is contained in CPU − the instruction register − whose bit pattern determines what the CPU will do. Once that action has been completed, the bit pattern in the instruction register can be changed, and the CPU will perform the operation specified by this next bit pattern.
Most of the modern CPUs use an instruction queue. Some instructions are waiting in the queue, ready to be executed. Different electronic circuitry keeps the instruction queue full while the control unit is executing the instructions. But this is simply an implementation detail that allows the control unit to run faster. The nature of how the control unit executes a program is represented by the single instruction register model.
How Instructions Are Executed
As instructions are simply bit patterns, they can be stored in memory. The instruction pointer register (also called program counter) always has the memory address of the next instruction to be executed. To execute this instruction, the control unit copies it into the instruction register.
The Instruction Execution Cycle
The CPU follows a systematic process to execute programs −
A sequence of instructions is stored in memory.
The memory address where the first instruction is located is copied to the program counter.
The CPU sends the address in the program counter to memory via the address bus.
Memory responds by sending a copy of the state of the bits at that memory location on the data bus, which the CPU then copies into its instruction register.
The instruction pointer is automatically incremented to contain the address of the next instruction in memory.
The CPU executes the instruction in the instruction register.
Go to step 3.
Steps 3, 4, and 5 are called an instruction fetch. Steps 3-7 make up a complete cycle, the instruction execution cycle.
Key Components
| Component | Function |
|---|---|
| Program Counter (PC) | Holds the memory address of the next instruction to be executed |
| Instruction Register (IR) | Stores the current instruction being executed |
| Address Bus | Carries memory addresses from CPU to memory |
| Data Bus | Carries instruction data from memory to CPU |
| Control Unit | Decodes and executes the instruction |
Fetch-Decode-Execute Phases
The instruction execution cycle can be broken down into three main phases −
Fetch − The CPU retrieves the instruction from memory using the program counter.
Decode − The control unit interprets the instruction and determines what operation to perform.
Execute − The CPU performs the required operation and updates the program counter.
Conclusion
Program execution in CPU follows a systematic fetch-decode-execute cycle. The program counter tracks the next instruction, while the instruction register holds the current instruction. This continuous cycle, supported by address and data buses, enables the CPU to execute stored programs sequentially and efficiently.
