How Does A CPU Work

This article discusses How does a CPU works. CPU is the computer’s heart and/or brain. It carries out the orders that are given to it. Its main job is to do math and logic operations and put the instructions together in the right order. Before we look at the main parts, let’s look at what the main parts of a CPU are and what they do:

How Does A CPU Work

A processor has two primary components.

  • Control unit — CU
  • Arithmetic and logical unit — ALU

Control Unit — CU

Unit of control The central unit (CU) of the CPU is responsible for orchestrating the execution of instructions. It instructs you on what to do. According to the instructions, it helps activate the wires linking the CPU to various other sections of the computer, including the ALU. The control unit is the first component of the CPU to receive a processing instruction.

Control units come in two varieties:

  • hardwired control units.
  • Micro programmable (microprogrammed) control units.

Hardwired control units are devices that need hardware changes to add or alter their functionality, while micro programmable control units may be programmed to change their behavior. Hardwired CUs process instructions quicker, although micro programmable CUs are more versatile.

Arithmetic and logical unit — ALU

Unit of arithmetic and logic As the name implies, an ALU performs all arithmetic and logical calculations. The ALU performs the addition and subtraction operations. These operations are performed by an ALU, which is made up of logic circuits or logic gates.

Most logic gates accept two inputs and output one.

Storage — Registers and Memory

The CPU’s main job is to do what its instructions say. It requires data to process these instructions the majority of the time. Some of the data are intermediate, while others are inputs and outputs.

Registers

A register is a tiny collection of storage locations for data. A register is made up of many locks. Latches, often known as flip-flops, are logic gate combinations that store one bit of data.

The output data is stored in registers on the CPU. Because it is intermediate data, sending it to the main memory (RAM) would be slow. This information is sent to another register through a BUS. An instruction, output data, storage address, or any other kind of data may be stored in a register.

Memory(RAM)

How Does A CPU Work

Ram is a collection of registers that have been organized and compressed in an efficient method to hold more data. RAM (Random Access Memory) is a volatile memory that loses data when the power is turned off. Because RAM is a collection of registers used to read and write data, it requires an 8-bit address, data input for the data to be stored, and a read and writes enabler, which functions similarly to latches.

What are Instructions

The granular level of computing that a computer may accomplish is called instruction. A CPU may handle many different sorts of instructions.

Instructions include:

  • Arithmetic, such as adding and subtracting
  • Logic instructions such as and, or, and not
  • Data instructions include move, input, output, load, and store.
  • Control Flow commands include goto, if goto, call, and return.
  • Notify CPU that the program has completed Halt

The computer receives instructions in assembly language, which are created by a compiler or are interpreted in high-level languages.

These instructions are built into the CPU. The arithmetic and logical operations are handled by ALU, whereas the control flow is handled by CU.

Computers can only execute one instruction every clock cycle, but contemporary computers can do multiples.

An instruction set is a collection of instructions that a computer can execute.

CPU clock
Clock cycle

The clock cycle of a computer determines its speed. The number of clock periods per second on which a computer operates. A single clock cycle is around 250 * 10 *-12 seconds long. The quicker the CPU, the higher the clock cycle.

The clock cycle of a CPU is measured in GHz (Gigahertz). 10 9 Hz is equivalent to 1 GHz (hertz). A hertz is equal to one second. and 1 Gigahertz is equal to 10 9 cycles per second.

The more instructions the CPU can execute, the quicker the clock cycle. 1 clock rate Equals 1 clock cycle CPU Time = clock rate / number of clock cycles

This implies that optimizing the instructions we supply to the CPU may boost the clock rate or reduce the number of clock cycles. Some processors allow you to raise the clock cycle, but you risk overheating and even fires since this involve physical modifications.

How does an instruction get executed?

How Does A CPU Work

The RAM stores instructions in a sequential sequence. An instruction for a hypothetical CPU is made up of OP code (operational code) and a memory or register address.

The OP code of the instruction is loaded into the instruction register(IR), and the address of the currently running instruction is loaded into the instruction address register. Other registers inside a CPU hold the value encoded in the final four bits of an instruction’s address.

Consider the following set of instructions for adding two numbers. The instructions and their descriptions are as follows:

STEP 1 — LOAD_A 8:

Initially, the instruction is recorded in RAM as 1100 1000>. The opcode is the first four bits. This determines the instruction. This command is retrieved through the control unit’s IR. The instruction is decoded as load A, which indicates it must load data into register A at address 1000, which is the final four bits of the instruction.

STEP 2 — LOAD_B 2

This loads the data at memory address 2 (0010) to CPU register B the same way as before.

STEP 3 — ADD B A

The next step is to add these two numbers together. The CU instructs ALU to do the addition and store the result to register A.

STEP 4 — STORE_A 23

This is a very basic set of instructions for adding two integers together.

Two numbers have been successfully inserted!

BUS

The bus transports all data between the CPU, registers, memory, and IO devices. The CPU puts the memory address on the address bus, the result of the sum on the data bus, and the correct signal on the control bus to load the data it just added to memory. Thanks to the bus, the data is loaded into memory in this manner.

Cache

The CPU also includes a technique for prefetching instructions into the cache. A CPU can execute millions of instructions per second, as we all know. This indicates that getting the instructions from RAM will take longer than executing them. As a result, the CPU cache prefetches certain instructions and data to speed up execution.

The data is classed as dirty if the cache and operating memory data disagree.

Instruction pipelining

Instruction pipelining is a technique used by modern CPUs to parallelize instruction execution. Fetch, decode, and run. The CPU may execute another instruction for the fetch phase while one is in the decode phase.

When one instruction is reliant on another, this poses a challenge. As a result, processors execute non-dependent instructions in a different sequence.

Multicore computer

It’s essentially a distinct CPU with certain shared resources, such as the cache.

The Brains of the Operation

How Does A CPU Work

The CPU is one of your computer’s most important parts. It does everything you expect a computer to do, and the other parts are mostly there to support it. Even though the same rules have been followed for many decades, there have been big changes, like adding more cores and using hyper-threading.

When put together, they make our computers, laptops, tablets, smartphones, and other connected devices stronger and, in the end, more valuable. But there are many things you can add to your current PC to bring it up to date and make it run better.

Conclusion

In computer science, the central processor unit (CPU) is sometimes likened to the brain since it is the most critical component of the computer. Computer operations are done by the CPU, which quickly runs program instructions. The speed of the CPU is a big part of what makes a computer power. Each new generation of microprocessors has a more powerful CPU and can carry out instructions faster than the last.

Please let us know your opinion in the comment section below.