Instruction cycle of CPU
The actual work performed by the CPU is to execute a sequence of instructions called a program. The instructions are stored in the computer’s memory. Almost all CPUs follow the fetch, decode, and execute steps, collectively named the instruction cycle.
Instruction cycle of a CPU
Fetch
The first step is to fetch an instruction. The instruction is stored in the computer’s memory. The location of the instruction is determined by the “program counter” or “instruction pointer”. Program counter stores a number that identifies the location of the next instruction
Decode
CPU will perform according to the instructions fetched from memory. A binary encoder then decodes the instructions. The binary encoder converts the instructions to signals that control the other parts of the CPU.
Execute
After decoding the instructions, the CPU executes the instructions. During this step, Control signals electrically enable or disable various parts of the CPU to perform the desired operation.
Block diagram of a uniprocessor CPU
Components of CPU
There are three main components of the CPU:
- Memory Unit
- Control Unit
- Arithmetic and Logical Unit
Source
Memory Unit
The memory unit is also called the storage unit. It stores the instructions, data, and immediate results. It is responsible for transferring information to the other units of the computer. It is the primary storage of the computer and is also known as Random Access Memory (RAM).
RAM
Control Unit
It controls the operations performed by the computer. It extracts the information from memory and then decodes and executes them. After decoding the information, it tells the Arithmetic and logical unit the operations it needs to perform and then sends the processed data back to memory.
Alsource
Also read, microprogrammed control unit
Arithmetic and logical unit
Arithmetic and logical unit (ALU) performs the actual arithmetic and logical operations inside the CPU. The control unit provides the instructions to the ALU that it needs to perform. ALU performs these operations by connecting transistors and then stores the result in an output register. As the name implies, ALU is comprised of two parts:
Arithmetic unit
It performs all the arithmetic operations such as addition, subtraction, and multiplication. ALU also performs complex operations by combining these arithmetic operations.
Logical unit
Selecting, merging, comparing, and matching the data is performed by the logical unit.
Source
Must Read hardwired and microprogrammed control unit and Difference Between Verilog and Vhdl
Frequently Asked Questions
What is the difference between RAM and ROM?
RAM stands for random access memory, and it stores the files that are used by the computer in real-time. It is volatile memory, and the data on it can be modified. ROM is Random Access Memory and is non-volatile, i.e., the data on it remains as it is even if the computer is switched off. Data on ROM cannot be modified.
How many instructions per second can be executed by a modem CPU?
A modern CPU can execute around a million instructions per second.
How is the speed of a CPU measured?
The speed of the CPU is measured by calculating the number of cycles the CPU executes per second. It is measured in gigahertz (GHz).
Conclusion
This blog talks about the central processing unit (CPU). We looked at its different parts and understood how they work together to execute an instruction.
Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, Machine learning, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc. You must look at the problems, interview experiences, and interview bundle for placement preparations.
Nevertheless, you may consider our paid courses to give your career an edge over others!
Do upvote our blogs if you find them helpful and engaging!