*Image of a wizard brain*

The Brain

You can think of a CPU as the brain of a computer. It is the most important component- in the sense that literally every operation goes through the CPU. The CPU is fed instructions and data, then performs operations on said data.

The two main types of CPUs in personal computers today are x86/x64 and ARM. For the purposes of these Tutorials we will focus on x86/x64.

How The CPU "Thinks"

As mentioned before, the CPU performs operations on data with instructions. It's really important to understand this idea, as it will make understanding abstraction easier later.

MOV, SHL, ADD, SUB and JMP are a few examples of instructions the CPU understands. These instructions are actually just mnemonics that represent the actual machine code the computer recieves, but more on this in Abstraction.

But what does all of this mean, and why is it important?

Inside The CPU

Cores. I think, or rather hope, everyone reading this has at least heard the word Core in the context of CPUs. This is going to sound insane, but a core is essentially a CPU inside of a CPU. NO, NOT RECURSION. The CPU of yesteryear was single core, so when you hear "quad-core," it's kind of like four of those single core CPUs in one cpu.

There are many components inside of the CPU itself, but what I'd like to focus on is registers. Registers hold data. The registers have specific names: AX, BX, DS, GS, SI, etc. The key thing to gain here is that these things exist.

Each core has it's own set of registers. There are also other components like flags, cache, ALU, etc but to keep things in scope, we won't worry about these things now.

Putting It Together

We have a CPU- it itself has components, it understands things, but what does all of this mean? Why is it important to understand?

We'll start with the latter question. It's important to understand, because the higher up you go the abstraction tree, the further you get from the seed. For example, you just wrote a program, performance is terrible, there's bugs, nothing executes consistantly. Where do you start troubleshooting? Having a deep understanding of how the hardware works will at the minimum give you a place to start.

Okay so, lets tie it all together and see how it works.

MOV ah, 0x0e

MOV al, 'x'

int 0x10

We are moving the value 0x0e into the first 4 bits of AX and the ASCII value of 'x' into the last 4 bits of AX. Then we call INT - interrupt 0x10. An interrupt signals to the CPU do something.

And voila, you execute this code, and the computer prints the character 'x' to the screen.

Conclusion

To keep things in scope, I'm going to leave it at that. I will ellaborate a little more on the code snippet above later. That gets into BIOS, and I will need to make that it's own section.

The main take aways are:

  • The CPU is the brain of the computer
  • It performs operations on data through instructions.
  • Registers are inside of the CPU, and they hold data.
  • The CPU understands specific instructions, and it does what you tell it to do.

As programming languages continue to abstract away details about the actual hardware, we stray further from understanding. We must remember that we're not communicating with the compiler; we are literally telling the CPU what to do.

< Last

.:CPU:.

Next >
Anon: "Spaghetti? Again?"