Skip to content
Back to writing

Beyond the Spec Sheet: The Complexity and Inner Workings of Modern Processors Part 1

Last updated

This is something that has always fascinated me. The intersection of hardware and software is something I’ve been curious about probably from the moment I learned about computers. How exactly does a random piece of metal do so much? How can it run such complex UIs, handle your selections, button clicks, and more?

A large part of it is possible due to a little thing computers have called a CPU. There are a lot of other components involved, but for the context of this discussion, we will stick to the CPU, which is one of the most critical ones. In this article, we will specifically be talking about this special and highly complex type of processor. Fundamental behavior remains the same across different types of processors, but a CPU is much more complex, and understanding it means you can understand most processors.

I covered some concepts about processors, like instruction sets, in a previous article (see x86-vs-arm64). I highly recommend reading this, as it will provide a valuable introduction and context that we will build on in this article. If you’re an advanced reader who already knows about bits and instruction sets, you can skip ahead. In this article, we will go over the parts of the CPU and exactly what each does in detail. This will act as a prerequisite before the second part covers the actual functioning. We are doing this because the entire explanation is very complex and would turn this article into a massive, difficult-to-digest piece.

Parts of CPU

Before we get into the nitty-gritty and the actual working, it’s important to understand the parts of a CPU. It is not a single uniform structure, but rather a mix of multiple complex components. We’ll define and briefly go over them here.

Keep in mind that we will only be going over the CPU here; modern devices often run on something called an SoC (System on a Chip), of which the CPU is just one part. Some of the pieces below may sound confusing. This initial definition is just to give you an idea. If you don’t understand exactly what something means or what the definition is trying to convey, don’t worry, we’ll go over each piece in detail.

  • Cores: Independent processing units inside a single CPU chip (such as dual-core, quad-core, or octa-core) that allow the processor to handle multiple tasks simultaneously. So technically, this is part of the CPU in the sense that a CPU can have multiple cores, but everything we define below is actually a part of one core. A core is basically a mini-CPU.

  • Control Unit (CU): It manages and coordinates all CPU operations (we will be splitting this down further for explanation below). For now, just consider this the main unit that decodes instructions provided to the CPU, defining the operation and controlling the flow of data between all the other units. Think of it as the brain of the CPU that coordinates everything.

  • Arithmetic and Logic Unit (ALU): If the CU is the brain of the CPU, then the ALU can be considered the heart. It performs the most critical functions that allow the CPU to work. As the name suggests, it handles the actual mathematical and logical operations (like ADD, MULTIPLY, etc.). We will go over exactly how it does this in detail.

  • Registers: Tiny, ultra-fast memory storage locations inside the CPU that hold data, memory addresses, and instructions currently being processed. We can split this into two parts: General Purpose Registers (GPRs) and Special Purpose Registers (SPRs). The special ones are for internal CPU usage and help the CPU function. We will go over them in detail later.

  • Cache Memory: A small, high-speed, volatile memory layer (L1, L2, L3) located on or close to the CPU chip. It stores frequently used data and instructions to cut down wait times when fetching from main memory (RAM). This is the easiest part to understand; we will go over L1, L2, and L3 and what they mean later.

  • CPU Clock (Clock Speed): A component that generates timing pulses (measured in GHz) to synchronize all internal operations and dictate how fast the CPU executes instructions. This may sound a bit confusing and unintuitive. When we get to the actual working, we will go over this. Until then, think of it as a fancy clock in your home that tells the system, “I need to leave at this time, wake up at this time,” and so on.

  • Buses: Internal communication pathways that transfer data, memory addresses, and control signals between the CPU and other components, like the motherboard and RAM.

I’ll dive into each of the above in an order that I feel will be easiest to understand.

CPU Architecture Map

Hover over or tap a component to see its role.

L3 CACHE (SHARED)L2 CACHECORE 1CONTROL UNITREGISTERSALUL1 CACHE
Select a component to learn more.

Cores

We defined earlier how a core is basically just a mini-CPU. It just so happens that a modern CPU isn’t one piece, but rather a bunch of CPUs glued together. This might be difficult to understand, so let’s use an analogy for simplicity.

Consider a company. If a company consists of just one person, then saying “the person is working” and “the company is working” means the exact same thing. That single person is the entire company.

A core is exactly like that person. If you only have one core, then your CPU (the company) and your core (the person) are the exact same thing. But if the company grows and puts 4 or 8 people together in a room to handle multiple tasks at once, the entire bundled group is what we call the CPU. Functionally, you could pull one person aside to do a job, and they are still a complete worker, just like how one core is functionally a complete mini-CPU.

L1, L2, and L3 cache

As mentioned earlier, this is just a cache. A cache is a fancy way of saying, “I want to access this fast.”

Consider you’re preparing for an exam. There is a large book that contains all the terms and syllabus that you actually need to study. Now, you might refer to the book a few times when you’re studying for the first time; however, when you’re revising what you’ve already studied, you would want to just go over the things that were useful to you, or that you actually want to understand. In this case, carrying a book around is a massive overhead, so you might just jot the relevant points in a notepad for later reference.

Cache is basically a notepad that we use because we want to reference the content quickly without actually having to go and see the book. So, what do L1, L2, and L3 mean?

  • L1 is the cache that lives inside the core, and is the easiest to access. In our notebook analogy, consider you kept a few flashcards attached to the cover of your notebook. You can read the most important parts easily without ever having to open the notebook itself. This would be the fastest way to get information, but understandably limited; you can’t exactly cover the entire notebook cover with flashcards. So, L1 is the fastest but also the smallest.

  • L2 is the cache that lives either inside (but slightly away from the main calculation unit) or right next to the core. In our notebook analogy, you can think of it as a bookmark. You might bookmark a few pages that are important. You’d still need to open the notebook, making it a bit slower, but it is still faster than going through every page. Now, reasonably, you absolutely could have more bookmarks inside your notebook than you could have flashcards outside it. So, L2 is very fast, but slower than L1, and also larger than L1.

  • L3 is the cache that is shared by all the cores. It is the largest and the slowest of the three, but still inside the CPU and faster than the RAM. In our analogy, you can consider it as the pages of your notebook. Not as fast as going to a bookmarked place or reading a flashcard, but still much faster and easier than picking up the entire large book.

Registers

Now, if you recall the x86-vs-arm64 article, we mentioned there that registers are just a temporary holding area where the data itself is stored. There are two types of registers as mentioned before: General Purpose Registers, which store the data on which an operation or an instruction is carried out (like storing two numbers, one in each register, that need to be added together), and Special Purpose Registers, which store multiple things internal to the CPU.

Consider the following special purpose registers:

  • Program Counter: This stores the address of the next instruction that needs to be executed.
  • Instruction Register: Holds the instruction code that was fetched from memory while the CU decodes it. To put it simply, this is the current instruction the CPU is working on.
  • Memory Address Register: Stores the exact place the CPU wants to read from or write to.

There are quite a few more, but we won’t go over each of them here.

As an analogy, consider the Special Purpose Register as a record keeper. Say when you play a sport, say, football; externally it looks simple: you kick a ball into the goalpost. But there might be a lot of things the teams would want to track. Which player is running the most? Who is kicking the ball the most? Who scored the most goals? Who got the most assists? All these are needed because they help a professional team track the game. Likewise, the CPU too needs a bunch of things tracked to be able to do its job properly. We will go over all of them later in another article in this series.

Clocks

Remember the wall clock analogy we used earlier? Well, it’s a bit more accurate than you might initially believe. If you observe closely, there is a very good chance that you’ve seen a clock or a watch that says “quartz.” Quartz is a crystalline mineral. Its special property is that when subjected to an electric current, it physically deforms and vibrates, and due to something called the piezoelectric effect, this vibration also produces an electric charge.

Quartz vibrates at a very predictable frequency. When clocks are built, based on this frequency, it ensures that one second actually is one second. The CPU uses the exact same mineral for the exact same reason, with just one minor difference: in the case of a CPU, the quartz crystal vibrates at a much higher rate, something like 100 MHz. This basically means it vibrates 100 million (10^8) times in one second.

This crystal is what helps a computer keep time and synchronize actions. When you do so many different things (like send a signal over this wire, store a signal from that wire, do this calculation, etc.) there is a very good chance that without a clock, these things go haywire and happen at their own pace.

Imagine you’re following a cookbook to make a cake, and the cookbook says something like, “Pour the batter into the mold, then keep it in the oven. Take it out of the oven and start icing.” You might do exactly what it said, but depending on how long you kept it in the oven, you might end up with a burned cake or the exact same raw batter you started with. This means the next instruction of “start icing” is completely ridiculous! The CPU uses the quartz crystal to keep time so actions happen at a predictable rate and you don’t end up with a corrupted mess that no one understands.

Now, you might have a question: “Wait, you said it vibrates at 100 MHz, but my computer and phone operate in the GHz range. That is much faster; how does that work?” Well, there is a special circuit called a Phase-Locked Loop (PLL). What this does is act as a multiplier to electronically increase the frequency of the clock. We will discuss this later in a separate article.

A clock has a series of lines moving out of it that connects to every single register, cache, the CU, etc. It’s a branching series of wires called a Clock Tree. The actual timing is tracked using a transition edge, the exact split-second the clock goes from a Low Voltage (0) state to a High Voltage (1) state. It acts similarly to a camera shutter. You click a photo, and the exact split-second the shutter clicks is the moment whose photo you end up with. Likewise, there is a specific circuit inside the CPU called the Edge-Triggered D Flip-Flop that does the same task of closing the shutter to allow everything to sync together. This, too, is beyond the scope of this article and will be discussed later.

Edge-Triggered Clock (1 Hz Simulation)

VOLTAGE STATE
1 (HIGH)
CYCLES COMPLETED
0
NOW

Notice the 📸 flash! Operations inside the CPU only lock in at the exact split-second the voltage goes from Low to High (The Rising Edge).

Buses

What’s the first thing that came to your mind when you heard this? Is it a large vehicle for ferrying people? If yes, you’ve in many ways identified why a bus is named as it is.

Think of this: we just said the CPU has so many components, it has the ALU, the CU, the caches, etc. Now, reasonably, all of them will need to talk with each other. So how does that work? Before we begin, if you remember the earlier context and if you’ve read the x86-vs-arm64 article, you’d know that all data is basically bits, which are 1s and 0s. Now we’re talking about a bunch of hardware, wires, pieces of metal, etc., so what exactly do 1 and 0 mean? Well, it means whether an electrical circuit is ON or OFF. So when we say anything about carrying or fetching data, it happens by controlling an electrical circuit that is either ON (high voltage) or OFF (low voltage).

Now imagine you have one light bulb controlled by one wire. In CPU terminology, we call it a “line” (with appropriate prefixes). What if you have 20 light bulbs, each being controlled by one wire? It means there is a collection of 20 lines. We call this a bus. It’s a bit of a crude way of defining it, but the easiest thing to understand it as is a series of wires.

There are three types of buses:

  • Data Bus: This is further split into two:

    • Internal Data Bus: This is exactly equal to the register width (32-bit or 64-bit). Inside a 64-bit core, these are 64 parallel wires so that a number can be pulled out of a register and slammed into the ALU in a single clock cycle.
    • External Data Bus: This is the highway connecting the CPU package to the RAM sticks. This will be all we say about it, as the exact process of fetching and contact with RAM is much larger and beyond the scope of this article.
  • Address Bus: This sits outside the core too. It is the bus between the core and the Memory Management Unit (MMU). This too is beyond the scope of this article, so we will avoid it for now.

  • Control Bus: It too is an external, public bus used by the Control Unit to dictate commands to components outside the execution core, like the external RAM sticks or the MMU (e.g., sending signals like “Hey RAM, I am doing a READ operation right now”). The exact working of this too is beyond the scope of this article.

Arithmetic Logic Unit (ALU)

As mentioned earlier, the Arithmetic Logic Unit is the heart of a CPU. Its role is to compute the answer for any given input. Now, the ALU isn’t a program or software. It is essentially a set of circuits, each of which has a role to do one specific task or operation. For example, there is a circuit for adding two numbers, another for subtracting two numbers, another for doing an AND operation, another for NOT, etc. We can go over how modern processors do this exactly in a later article. However, for now, consider all these as hardware operations. If you’re not familiar with them, you can refer to the Wikipedia article on bit operations.

Here’s an extremely important thing: modern CPUs actually have multiple ALUs in a single core instead of just one. This is so that it can execute multiple instructions at the exact same clock tick.

(Refer to the illustration below to get an idea of how the ADD operation works. If you input two numbers, the circuit will calculate their sum, highlighting the process for it.)

4-Bit Ripple-Carry Adder

Change either digit. Each column is one full adder, and a green wire is a 1. Carry leaves a column as Cout and enters the next as Cin.

0011 + 0101 = 01000

3 + 5 = 8

0Bit 0×1A 1B 1Cin 0S 0XORANDXORANDORBit 1×2A 1B 0Cin 1S 0XORANDXORANDORBit 2×4A 0B 1Cin 1S 0XORANDXORANDORBit 3×8A 0B 0Cin 1S 1×160XORANDXORANDOR
How it works: Bit 0 starts with Cin 0. In each column the first XOR and AND combine A and B. The second XOR writes the sum bit, and the second AND plus the OR produce Cout, which is the next column's Cin. The last Cout is the ×16 bit, so two digits can add up to 18. This sum is 3 + 5 = 8, and the final carry is 0.

A reasonable question that can come up now is: if there are so many circuits and so many operations in one ALU, then how does it know which one to do?

The answer is pretty simple: it doesn’t. So, it does all of them. The internal data bus from the register comes into the ALU where it permanently splits into identical lines, such that each of them is basically a duplicate of the data in the bus. This is the exact same thing that happens in your home. The electricity company doesn’t give you dozens of different connections for your lights, fans, etc. They give you a single metered power line. What happens is that this line is then split in parallel so all your electronics are basically connected to that single power source.

ALU Multiplexer (The Track Controller)

Change the numbers. Notice how ALL circuits calculate instantly, but the MUX only connects one answer to the output.

ADD CIRCUIT
9
SUB CIRCUIT
3
AND CIRCUIT
2
OR CIRCUIT
7
MUX
Decoder Signal
FINAL OUT
9

So, when data reaches an ALU from the registers, every single circuit is activated at the exact same point and carries out its operations. While this is happening, the decoder present in the CU decodes the instruction and the operation to be performed in parallel.

At the end of all the circuits, there is a special circuit called the Multiplexer (MUX). Think of it as analogous to a railway track controller. Technically, all the tracks are valid and could have trains running on them, yet it is the track controller who guides and decides which track leads to a specific railway station platform. The multiplexer determines which operation’s output is the actual output needed.

This should bring up a few questions: “Why can’t the multiplexer be at the front? Isn’t activating all the circuits together power-consuming?” The answer is as follows: if you keep it in front, you have to suddenly stop the operation, wait for the decoder to complete, and when the data comes in from the internal data bus, only open up the ones that lead to a specific operation. This creates two difficulties:

  1. It slows the CPU down: Suddenly you need multiple cycles to complete a single task (a cycle is one low-to-high voltage transition, followed by high-to-low, and then the next low-to-high).
  2. Circuit complexity: You need to create a very difficult circuit to control so that data only enters the right circuit.

Is the current approach power-consuming? Yes, it is, but it isn’t a massive power consumption, and the simplicity actually makes the design much easier and way faster. Modern CPUs do have a lot of logic for power saving too, but we won’t go over those here as it would needlessly complicate things. They will be covered in a future article though.

Control Unit

We started this article by saying the Control Unit is the brain of the CPU. It is responsible for controlling and coordinating all the operations of the CPU. It fetches instructions from memory, decodes them, and then directs the ALU and other components to execute them. The CU also manages the flow of data between the CPU and other parts of the computer, such as memory (RAM).

The CU is not a single circuit; it is a set of highly specialized circuits working in tandem to ensure the CPU operates correctly and efficiently. The components are:

  • Instruction Decoder: It is the hardwired switchboard logic. It takes the binary code currently sitting in the Instruction Register (IR), scans the bits, and activates the specific internal control lines for that command, which it then sends to the multiplexer in the ALU to select the correct operation.

  • Timing and Control Logic: This component connects directly to the CPU Clock. It ensures that signals are sent in a precise, rhythmic sequence. For example, it makes sure a register opens before the ALU tries to read the data bus, not at the same time.

  • Control Line Array: A massive network of dedicated, point-to-point wires traveling out of the CU to every single component in the core (ALU, Registers, Multiplexers, Caches).

We won’t go over the exact process as to how it works here; there are concepts like the Fetch-Decode-Execute cycle that define how the process itself flows. Likewise, we won’t go over exactly how it fetches memory from RAM. But before we move on to the next article, one important thing that should be covered here is how it sends the opcode and the exact data that needs to be processed to the ALU.

The CU sends the control signal to the multiplexer in the ALU, which selects the correct operation circuit. Simultaneously, while the decode operation is being performed, it reads the register bits (see the x86-vs-arm64 article for details on the bits in an instruction set).

Now, the instruction set only tells the CPU which register it must point to by way of a 5 (or so) bit address, essentially, which register should be read and which should be written to. It doesn’t have any idea of the actual data inside these registers. The CU sends signals via the Control Line Array to the specific registers, which then open up and send the data to the internal data bus. The ALU then reads this data and performs the operation.

Think of the CU as the CEO of a company. The CEO doesn’t go to every person and dictate exactly how they should do their daily tasks; rather, they coordinate and guide everything. They ensure that what sales tells the customer about a product is what development is actually building, and that the cost mentioned is the one the finance team has signed off on. They coordinate with the teams to ensure deliverables are completed on time, and most importantly, they distill what a customer may want to set the future direction. A Control Unit does pretty much the same thing: understanding instructions and then coordinating everything else to make it happen.


So, that’s a wrap for Part 1! We’ve discussed all the individual units that are present as part of the processor. In the next article, we will go over exactly how they work together. You might already have an idea or a guess as to how it all ties up, but we will deep dive and explore the exact functionality. I hope this was useful and helped you understand how complex a somewhat trivial piece of metal can truly be.

Suggested next reading