Take a moment to sit back and relax. Just look around yourself. What do you see? Nah, I am not talking about your annoying roommate or your neighbour’s mad dog. What are those things that are so into your daily life, that you don’t even notice them? If you guessed it correctly, then yes, I am talking about the electronic devices all over your place.
The laptop on which you are reading this blog, the smart television that you own, the Google home that you bought 6 months ago, the fitness band on your wrist and yes, not to forget, your goddamn smartphone(beep)! You just cannot imagine your life without these gadgets. Yes, even if John Lennon were alive, he couldn’t have “imagined” his life without such stuff!
But do you know about that small, tiny piece of silicon which operates these devices? Well yes, you probably do. Yeah, I know, that you know, that it is the CPU aka the Central Processing Unit.
You might want to have a look at: Intel’s naming scheme decoded
But do you know how it works or what are those fancy cores for and you simply don’t understand why gamers overclock their systems? If not, then you have landed on just the right blog, the only blog that you need.
Studying CPU as a whole and in detail will cost you a big chunk of your time. In this blog, I will be talking about the basic and necessary stuff that you need to know.
What is a CPU?
In complete technical terms, a CPU is an electronic circuit within a device, to carry instructions of a computer program by performing basic arithmetic, logical, control and input-output operations, which are specified by the user.
In simpler words, the CPU literally controls almost every aspect of an electronic device. When you, the user, perform an operation, like, typing a word on your keyboard or touching your phone’s screen to launch an application, the CPU gets active. It identifies the input signal generated by the user, the logical unit breaks down the instruction to understand what the user demands and generates the output while the control unit lays down a connection between the control unit and the output device to deliver the desired output.
Woah! Don’t get overwhelmed. Down the blog page, I will be getting into a bit of detail, so that you understand it all well. Now to add a bit more to your knowledge let us move further.
The CPU is simply called the processor. And most modern CPUs that we have on our smartphones or laptops are called microprocessors. A microprocessor is a processor whose electronic circuitry is small enough that can be contained on a small piece of a silicon wafer.
This small piece of silicon is called an Integrated Circuit or simply an IC. An IC can be as small as a key of your keyboard, maybe even smaller. Sometimes, to perform complex operations, some discrete devices are connected to the microprocessor. It makes the microprocessor a complete functional unit. We simply call it the MPU. As technology has advanced we have integrated the MPU with memory, input-output units etc. on a single IC, called microcontroller.
You might have heard of people carrying on some sort of projects on Arduino or Raspberry Pie. The basic difference between the two is that an Arduino is a microcontroller and a Raspberry Pie is a microprocessor.
So how does a CPU work?
You will now be going through some serious stuff. Understanding the working of a CPU is not a cup of tea.
Though you need to be a bit more attentive.
A CPUs main job is to take up all the instructions by the user and execute them. Our user gives a sequence of instructions. This set of instructions is called a program. These instructions are needed to be stored in some sort of memory. When these instructions are stored in memory, they are also assigned a memory address. The CPU uses these memory addresses to identify a particular instruction.
How memory works
Take this, for example, You must have seen your school teacher maintaining a register or an Excel sheet to enter the information of every student. Each student is assigned a serial number or a roll number. Now if your teacher wants to access some information of a particular student, she will directly search for the roll number assigned to the student and get the information. This is how it works. Replace your teacher with the CPU and her register with memory and your roll number is a memory address.
This will give you a rough intuition of the memory. Although it’s not exactly how memory looks but for the time being, this example will work
The three major steps
The CPU works in mainly three steps: Fetch, Decode and Execute:
- During fetch, the CPU simply retrieves an instruction from program memory.
- While decoding, the CPU breaks down the instruction into simpler chunks.
- During execute, it performs the required operation.
The decoding of an instruction is something to muse about.
Instructions and Instruction Set Architecture
Instruction decoder is circuitry which performs decoding. The instruction is converted into signals, that control other parts of the CPU. The CPUs Instruction Set Architecture (ISA) defines how to interpret an instruction. ISA is nothing but a set of instructions that a CPU is capable of performing. But how a specific instruction is performed, depends on the micro-architecture of the CPU.
An instruction is nothing but a group of bits carrying certain data. One group of bits, within the instruction, indicates which operation is to be performed. This group of bits is called an opcode. The remaining bits carry the values and addresses of the operands (operands are the pieces of data on which the operation is to be performed).
After the execution is complete, the entire process repeats with the next instruction cycle normally fetching the next-in-sequence instruction because of the incremented value in the program counter. Now wait a minute, what is a program counter? The program counter is a register (used to store data) which stores the memory address of the instruction to be executed. It is with the help of a program counter, that the CPU gets the memory address of an instruction.
Generally, when an instruction is fetched, immediately after that, the value in the program counter gets incremented and it holds the memory address of the next-in-sequence instruction. So, when the on-going instruction gets executed the CPU automatically moves on to the next instruction.
We’ve got our CPU running, but we need something to control its activity. We use a clock pulse for that. An external oscillator circuit generates a series of pulses in the form of a periodic square wave. The CPU operates whenever the pulse is high and is disabled when low. The frequency determines the rate at which our CPU operates. Higher the frequency, the faster a CPU is.
But wait a minute. Why do we need a clock pulse after all? Why can’t we just let the CPU operate at all times? What’s the need to disable it?
At micro levels, things move fast. The signals in a CPU travel in fractions of a second. We, of course, have lags which occur at micro levels.
Let us suppose an instruction requires an operation to be performed on multiple numbers of inputs. It is possible that there is a lag in the process of getting a few inputs. If our CPU is always enabled, it is possible for it to calculate the output even before all the inputs are taken in. This would create chaos.
It is also possible, that our output is the input for the next instruction. To avoid these kinds of chaotic situations, we use a clock pulse. So enough time is given to the inputs to settle.
We have come a long way, from using the vacuum tubes to transistors. Its all about speed and performance.
Instruction is divided into a number of processes, called threads. These threads are then processed by the CPU concurrently (in a parallel fashion). This naturally increases the speed of a processor. This technique increases the utilization of the CPU.
Multiple processing units share the memory. Each processing unit has its own hardware. When all the required units are integrated on a single chip, an individual unit is called a core. They can cooperate on the same program and programs can migrate from one unit to another.
Therefore, a single processor can run multiple instructions on separate cores at the same time.
The techniques of multi-threading and multi-processing combine together to achieve even higher performance and speeds.
32/64 bit CPU
Memory must store programs during execution. The memory contains a large number of semiconductor cells, which can store 1 bit each. A group of these cells is called a word. Now, information is not stored in these cells individually but instead is processed in words.
Word length is the number of bits in a word. It can vary from 16 to 64 bits.
If the word length is 32 bits our CPU is called a 32-bit processor. In layman’s language say that a 32-bit CPU can handle operation on 32 bits at a time.