How a CPU works.
How a CPU works.
So recently I found out that most people involved or not with programming have no idea how a CPU works.
This bothered me.
And I didn't like that.
So I decided to find why this was the case. And the more I though about it I realized that most people never have to deal with a CPU in programming at all.
For most of you, programming is about variables, classes, functions, ect. And all of that is too high level to ever need to worry about a CPU.
The only reason you would need to is out of curiosity.
And I'm here to help you sate that curiosity.
What is a CPU?
I'll make this one short due to the fact that most of you probably know what a CPU does at a higher level already.
In short, a CPU or Central Processing Unit is what does all the actual computation in your computer
It can also interface with the other components in your computer.
What is inside a CPU?
At a very low level a CPU is just a ALU, and registers.
The ALU or the Arithmetic and Logic Unit is where all the Arithmetic and Logic happens.
Inside the ALU is what is known as logic gates.
These are little electrical circuits that when given any input return (out the other end) a output via electrical wire.
Lets look at an example.
The AND Gate
The and gate only returns a 1 (or an electrical current) when all of the inputs are 1 (or on).
Back to the ALU.
The ALU consists of these gates and they can perform logic.
When these gates are put together you can make some cool things.
Such as adders.
A Computer needs to store things its working with.
This can be done via RAM.
Or a few registers inside the actual CPU.
These are just little circuits that can store values.
The fetch and execute cycle.
The CPU needs stuff to do.
So it has instructions in RAM.
These instructions can tell the CPU to do certain things.
But how does it get these?
It uses a cycle.
Firstly it fetches the binary instruction from RAM.
Then it decodes it.
Then it executes whatever the instruction said to do.
Congrats! We have learned about a simple CPU!
It can execute instructions that are in RAM and store values in internal registers!
I hope you enjoyed.
Upvoting is caring :) - @Bookie0 2020
I love the fact that you post a tutorial every single day. EVERY SINGLE DAY. That's so outrageous, you cycle-farming spammer.
Dude, stop being childish. I make full courses now and not multiple-parters. I've already responded to your demands and improved. These tutorials teach people and help them learn. Unlike some project you may or may not make that people may look at for a second and never use again. Some of this stuff I teach people, for example Clean Code, can stick with them for a long time unlike some repl. Please stop holding a grudge against me for no good reason. All you are doing is proving yourself to be immature. By posting one every single day I am just helping people learn more often. Cycles don't really matter to me, it's just a number. Doesn't prove anything and or help you in the long run. So next time, consider what you're saying before you make a comment. @johnstev111
I used to do it. You really should research your stuff before jumping onto a bandwagon, kid. My stuff is now one-off.
I make full courses now and not multiple-parters.
I could've milked this and made it into a series for an epoch. Alas, I didn't. Please think before you act, johnstev. @johnstev111