Skip to playerSkip to main contentSkip to footer
Get a clear, beginner-friendly dive into how your CPU works! This video explains the fetch-decode-execute cycle, the role of the clock, instruction pointer (RIP), and units like the ALU and cache. Learn why timing matters and how your CPU handles instructions step-by-step. Perfect for gamers, coders, or anyone curious about what makes computers tick. Inspired by Kip Irvine?s Assembly Language for x86 Processors, this is your gateway to understanding computer architecture. Subscribe for more tech insights and hit that QR code to explore more tutorials! #CPU #ComputerScience #TechTutorials

Introduction to CPU Operations 00:00:00
CPU Clock Explanation 00:00:17
Clock Cycle and Stability 00:01:07
Instruction Fetch from RAM 00:03:24
Instruction Pointer (RIP) Role 00:03:48
Sequential and Conditional Execution 00:04:49
Code Cache Functionality 00:06:24
Instruction Decoding Process 00:07:51
Control Unit Operations 00:08:33
Arithmetic Logic Unit (ALU) 00:08:52
Floating Point Unit 00:11:03
Data Cache Usage 00:12:08
Summary of CPU Process 00:14:36
Closing and Subscription Call 00:15:07

Thanks for watching!

Find us on other social media here:
- https://www.NeuralLantern.com/social

Please help support us!

- Subscribing + Sharing on Social Media
- Leaving a comment or suggestion
- Subscribing to our Blog
- Watching the main "pinned" video of this channel for offers and extras

#CPU #ComputerScience #TechTutorials #ComputerArchitecture #AssemblyLanguage #TechExplained #CPUBasics #LearnTech #x86Processors #Coding
Transcript
00:00hello there let's talk about how your cpu fetches decodes and executes instructions
00:12we're going to just do a quick surface level overview but i hope you like it
00:17okay so for starters um your cpu has something called the clock
00:21if you see this graph right here whoops i forgot to keep my pen onto one monitor here let me just
00:30double check that real fast okay is it working yeah okay so
00:40okay so notice how we have this line that goes up and down and up and down it kind of looks like a
00:45little binary line uh it actually is uh sometimes your cpu is outputting a zero to this special
00:52circuit that we call the clock and sometimes it's outputting um a one and it just oscillates
00:57between zero and one constantly it goes zero one zero one zero one it does so very very very very
01:02fast and the reason it does that is because uh something needs to control um the timing of your
01:09cpu imagine this we kind of take this for granted but when you apply electricity somewhere as a human
01:15you kind of feel like the electricity goes to the other place like on the other side of your house
01:20or your room or whatever you kind of feel like it goes there instantaneously because it's really
01:24fast but in reality electricity doesn't go faster than the speed of light so there is a limit which
01:30means if you have a cpu that is executing instructions really really really really fast
01:35you know fetching instructions from your system ram really really fast
01:38there's there's there's there's the problem of trying to um to know for sure that the electricity
01:46actually made it uh to the other place in time uh so like what if we said let's load some instructions
01:52from memory they come down the wire to your cpu how do we know when it actually finished coming down
01:58the wire to the cpu we should take it for granted but in reality physics has a limit and so the electricity
02:04needs time to get there and it needs time to stabilize so the clock cycle uh helps us with
02:10that timing so you know if we make the clock go too fast your cpu becomes unstable your gamers
02:16you gamers probably know that um if we make it too slow then it'll work but um you know we're not
02:22getting the fastest you know cpu uh that that we that we can we're not getting all the performance out
02:27of it that we can so we make it we make the clock cycle go as fast as we can uh without making the cpu uh
02:33instable and so just keep that in mind that's one component of the cpu okay so then the next thing
02:41i wanted to show you oh and by the way let me give credit to the authors of this book i'm just looking
02:45at a diagram but um this book is written by someone named kip irvine and it's titled assembly language for
02:52x86 uh processors it's written by pearson or it's published by pearson and the year is 2014.
02:58so uh get a copy get a copy of this book anyway uh so this is a simplified cpu block diagram
03:06let me get my notes here real fast so i don't forget what i was supposed to say
03:10clock ticks and alu okay so i guess that's pretty much it so um imagine now
03:18that um we have a little ram stick or some place where we can get uh instructions for the cpu so this
03:24is like system ram will say and we'll just pretend for the sake of argument that we already have
03:28existing circuitry that will easily transfer data back and forth from the ram stick to the cpu so
03:34anytime the cpu wants to grab some kind of data or like an instruction or something off the ram stick
03:40it can just do it and that's the arrow right there so the first thing that we should keep in mind after
03:44that is that there is a special register in the cpu called the instruction pointer rip in x86-64 assembly
03:52the rip register and the rip register it basically just holds a memory location telling the cpu where
04:00is the next where's the address of the next instruction that we want to execute so you know
04:05imagine you have like some kind of memory address 0x i don't know 55 and then you wanted to execute
04:12an instruction on the very next actually let's do five zero so i can increase this by eight without
04:17doing hex in my head we'll say this is like uh the address five zero in hexadecimal so that means
04:24that the next time the cpu wants to execute an instruction it's just going to ask system ram
04:28for that address system ram is going to give it whatever ones and zeros it has and then it can be
04:34decoded and executed after that and then of course we have to execute a program uh you know step by step we
04:41have to execute more instructions and we can't just do one instruction
04:45so typically in a program you execute instructions one by one by one by one by one
04:49and then every once in a while there might be some decision logic like you have an if else
04:54uh branch like let's say uh you know for the for the high level people i'll put a question mark here
04:59you have like an if statement and you say like if that's true then execute this
05:03i'll put maybe i'll put this in as a green line uh otherwise if it's not true uh then we'll just
05:09execute this other logic down here so you know very often we execute instructions sequentially
05:15but every once in a while we have to jump right because if if you executed this if statement and
05:19you realized that this condition was not true then you could not execute the body that came right
05:24after the comparison instructions you would have to jump down to wherever the else block is so
05:30um there is circuitry inside of the cpu that allows you to either increase the instruction
05:36pointer by eight bytes eight bytes because 64 bits per instruction because that's your cpu
05:41so you just kind of go sequentially or to jump somewhere because you made a decision or you're
05:46like making a function call or whatever so just keep in mind that under the hood under this diagram there
05:51is a lot more logic even than the uh the more detailed diagrams that you can find elsewhere there's
05:58just like a lot more detail so anyway the rip uh register just kind of increases by eight
06:03every time we execute instruction sometimes it'll drastically change its address so we can jump
06:08execution somewhere else in order to make a decision so just keep that in mind so suppose that we just
06:14fetched an instruction from memory you know it comes uh comes in here and uh you know we kind of send
06:21it down the line we first give it to the code cache unit your cpu is just not a solid block of stuff
06:27it's got you know subunits inside of it and one of these units is the code cache unit
06:31um it's a lot more complicated than what you're seeing here but basically
06:36system ram is very slow dealing with the cpu internally is very very very fast in comparison
06:42so if we have like a register or some unit that we're accessing that's inside of the cpu it's
06:48lightning fast compared to accessing the memory so that means cpus have caches which just i'm not
06:54going to go too much into caches for this video but basically every time we get a new instruction
07:00we might put it into the cache which is like incredibly fast because it's hardware that's
07:04part of the cpu then maybe sometime in the future we might want to execute the same exact instruction
07:10at the same exact address again that's possible remember we have loops we can execute the same
07:15instructions a bunch of times in a row so if we come across an instruction that we have executed in
07:21the past and it's already in the code cache then we don't actually need for mem we don't we don't
07:26actually need to wait for memory to fetch the instruction for us we can just go directly to
07:30the code cache and it's a dramatic speed up remember when you access memory uh execution has to stall
07:37for quite a long time usually or sometimes okay so that's what the code cache does once the memory
07:44and the code cache have figured out okay we're we got the instruction and everything's good then we just
07:49sort of decode the instruction we decide you know what is in the instruction uh is is this 64 bits
07:55is it all uh like data or is it all like uh like is it half and half and part instruction part data part
08:02whatever there's lots of different formats for instructions so the instruction decoder just sort
08:07of like you know decides uh how to separate it and it sends data into the uh control unit notice how
08:14there's a little arrow pointing from the instruction decoder to the instruction pointer so we could use
08:19that information to decide how to modify the rip register like if we're going to go sequentially or if
08:24we're going to jump somewhere uh and then the uh let's see when we send uh the instruction to the control
08:33unit the control unit is it's not necessarily the brain because the whole cpu is the brain of the
08:38computer but the control unit is kind of like the decider of the cpu at least that's the way i see
08:43it it decides what to do there's a lot of other subunits in the cpu notice how down here we have uh
08:50you know cpu registers and we also have the all you of the all you is basically the arithmetic logical
08:56unit so it's it's a little subunit that will execute mathematical instructions or logical instructions
09:01like it'll take some bits and it'll it'll move them to the left or to the right or it'll flip the bits
09:05or whatever or it'll add two numbers together the registers you know they're very very very fast
09:11they're like you know the variables of the cpu um so the control unit will examine uh whatever it's
09:17getting and it'll decide all right what does this instruction want us to do it wants us to add two
09:22integers together or it wants us to write something to memory or it wants us it wants us to do whatever
09:28right so when the control unit uh receives input remember this is all just like ones and zeros
09:33right so imagine if we had like a bunch of ones and zeros coming in and they're just wired directly
09:38into the control unit right so then the control unit has its own internal circuitry that uh that
09:45makes it so well if i receive this number then i'm going to tell everybody else to add numbers together
09:50and if i see some other number i'm going to tell everybody else to multiply numbers together so
09:54the control unit is really responsible for deciding what the other units need to do in order to
10:00accomplish uh the current instruction so gosh i really need to fix this i just reconfigured this
10:07thing and now it's just like drawing even when i don't want it to draw so uh the control unit let's
10:15say that we did that we have like an addition instruction we want to add two registers together
10:19the control unit will send this down the wire to let the all you unit know that it needs to perform
10:24addition the all you unit also has inputs and based on what it receives it will decide to do
10:29something it'll decide to add or subtract or multiply or just whatever so the control unit sends the
10:35right input into the all you unit so that it knows to add or do whatever we wanted it to do
10:41and the all you unit also receives the operands like it might receive data that just came from memory
10:46it might receive registers it might receive just like a raw immediate number that's embedded into the
10:51instruction um on the other hand uh we might also send something into the floating point unit so
11:00the control unit uh it's always sending all of these signals to all of its you know connected units
11:07these wires it's not like we can remove these wires so there's always something even if it's a zero
11:11going down the line so the control unit will basically send the right signals down to the all you
11:17to tell it you're going to add and it'll send the right signals down to the floating point unit to
11:21say uh you're not going to do anything or just we're not we're going to ignore the result there's
11:28like all these logical gates that we're not showing on this diagram where we can just like ignore
11:32the output result of some unit that we're not going to use so it's sending all these signals to
11:37these units so these units can know what to do um just like a quick note here the all you only deals with
11:44integer math and uh you know bitwise logical operations floating point numbers in the machine
11:49are stored totally differently than integers so we need a totally different unit in order to process
11:54them so that's why there are two units there uh well i mean i guess depending on you know what cpu we're
12:00talking about but like as far as the ones that i'm aware of and that i use so then um you know the
12:07data cache kind of the same thing um you know there's like a code cache up here and a data cache down
12:12there so sometimes we might want to fetch data that we've already fetched before and we don't want
12:16to hit system ram so you know we don't want that slow down so we'll just take it from the cache
12:21and um we will also populate the cache when we have a result so when this like all you is done adding
12:27whatever it's going to add it'll send its result data to the data cache and then um you know uh like
12:34on the next clock cycle or two or three or whatever then uh we can reuse the result in another
12:40instruction or send it back to memory or do whatever we want to so this is like a basic
12:46idea right like you you start off by you know grabbing something from memory uh possibly if
12:53it's already in the cache then you wouldn't actually grab it and then the instruction decoder decides
12:57you know are we gonna we're gonna jump are we gonna go to the next instruction after this is over
13:01so it'll have the next address prepared uh notice how there's kind of like a little cycle that goes here
13:07between code cache instruction decoder and instruction pointer and um so you know we're
13:12always kind of deciding what's the next instruction that we're going to execute and then we like you
13:16know uh send the decoded instruction to the control unit the control unit decides you know are you going
13:22to do some addition are we going to use registers or not and then you know like are you not going to
13:26do anything or are maybe you are going to do something in this case i'm just saying the floating
13:30point won't do anything if we're going to add integers and then once that is all processed you
13:35know it comes to the data cache and um well we can we can basically just uh you know write it back
13:43to memory i think this diagram is not showing an arrow that will write it write it back to memory um
13:51yeah the code cache is definitely not going to feed directly into memory that's just a cache
13:55but yeah so imagine like there's a there's like another wire here that goes to system ram
14:00so when we have a result we can just write it into system ram
14:05let me see if i forgot to say anything rip
14:12yeah that's basically all i wanted to say okay so now you have a fairly good idea of at least one
14:18level deeper of what's going on inside of your computer how the cpu in a general way loads instructions
14:25from system ram and and decodes them and and all these little sub units getting told what to do
14:30and the results getting piped back to the instruction pointer and also to system ram and so forth and it
14:36just keeps going like this again and again and again and also just remember that um at certain
14:41points during even one cycle uh we wait for a clock tick i'm not going to say exactly when we wait
14:47because it's kind of specific to what's going on it's beyond the scope of this video but um yeah the clock
14:53speed controls how fast these cycles go and there's much more advanced stuff that you could
14:58learn later uh like pipelining and such to increase efficiency but this is a basic idea
15:04of how your computer works i hope you enjoyed this video i hope you learned a little bit of stuff
15:09and had a little bit of fun i'll see you in the next video hey everybody thanks for watching this
15:15video again from the bottom of my heart i really appreciate it i do hope you did learn something and have
15:20some fun uh if you could do me a please a small little favor could you please subscribe and follow
15:26this channel or these videos or whatever it is you do on the current social media website that you're
15:31looking at right now um it would really mean the world to me and it'll help make more videos
15:36and grow this community so we'll be able to do more videos longer videos better videos or just i'll be
15:41able to keep making videos in general so please do do me a kindness and uh and subscribe you know
15:48sometimes i'm sleeping in the middle of the night and i just wake up because i know somebody subscribed
15:52or followed it just wakes me up and i get filled with joy that's exactly what happens every single
15:56time so you could do it as a nice favor to me or you could you could troll me if you want to just
16:01wake me up in the middle of the night just subscribe and then i'll i'll just wake up i promise that's
16:05what will happen also uh if you look at the middle of the screen right now you should see a qr code which
16:11you can scan in order to go to the website which i think is also named somewhere at the bottom of this video
16:16and it'll take you to my main website where you can just kind of like see all the videos i published
16:21and the services and tutorials and things that i offer and all that good stuff and uh
16:28if you have a suggestion for uh uh clarifications or errata or just future videos that you want to see
16:34please leave a comment or if you just want to say hey what's up what's going on you know just send me
16:39a comment whatever i also wake up for those in the middle of the night i get i wake up in a cold sweat
16:43and i'm like it would really it really mean the world to me i would really appreciate it so again
16:50thank you so much for watching this video and um enjoy the cool music as as i fade into the darkness
16:58which is coming for us all
17:06so
17:16so
17:22so
17:41so
17:47so
18:01so
18:05so
18:11so
18:29so
18:31so
18:33so
18:56so
18:58so
19:20so
19:22so
19:47so
19:49so
19:59so
20:01so
20:03so
Be the first to comment
Add your comment

Recommended