What’s Your Computer Actually Doing?

What’s Your Computer Actually Doing?

Articles, Blog , , , , , , , , , , , , 100 Comments

Every modern computer, when you get
right down to the bare metal, is doing basically the same sort of thing. I’ve said before that computers are just
overgrown calculators, but how do you go from a simple calculator
to playing video games, sending stuff over the internet, or even decompressing and displaying
the millions of pixels in this video? In short, what’s your computer
actually doing? Behind me is a scaled-up version of a computer, but we’re going to go much, much simpler. If you take apart your phone or PC, somewhere in the heart of it will a
Central Processing Unit, or CPU, connected to all the other devices
that make it work. Now, to show a really basic example,
we’re not going to use all those devices. The first one we are going to use
is the clock. With every tick of the clock, our CPU goes through a step in what’s called
the “Fetch-Execute” cycle, or “Fetch-Decode-Execute”. This clock is slightly magic, in that it ticks (click) every time (click)
I click my fingers. (click) (click) In the CPU I’m going to have three registers. These are bits of fast storage where the CPU
holds values that it’s working on right now. These are: a register that keeps track of
our instruction cycle, another that loads our instructions from memory, and an Accumulator. The final thing we need in our simplified
computer is somewhere to keep the instructions and any values that we end up calculating. That is RAM, Random Access Memory. We call it Random Access because it
doesn’t matter when or in what order the information is read or written. So: that is our computer. Let’s run a simple program. All it’s going to do is count up. The processor has three steps:
Fetch, Decode, Execute. It will just repeat those on a loop, that’s the one thing that’s
actually built into it. So we need some instructions,
actually in memory, so let’s load our program into RAM. The RAM is also used to store our answers,
our outputs. In the real world,
these would all be stored in binary, but let’s not overcomplicate things right now,
let’s keep them human-readable. An instruction has two parts. The first part is the instruction itself. And the second part is usually
a memory address. On each clock tick, the CPU will do
one of three things: It will fetch an instruction from
a memory address. It will decode that instruction. And it will execute the instruction. Round and round in a loop.
So it’s going to count up. We’re going to begin with a number, and add one to it, over and over again. (click) Fetch. One clock tick.
The Program Counter is set to 0, so the CPU fetches the instruction at address
0 in the memory and puts it into the instruction register. (click) Decode. The CPU decodes the instruction. The first part is the instruction, and the second part is a location. In our case, the instruction is LOAD
and the address is 6. So we will be loading the value in
address 6 into the accumulator. (click) Execute. The CPU executes this instruction. It takes the value at address 6, and loads it into the accumulator. In this case the value is 1. (click) Fetch. The program counter is incremented, and the CPU fetches the next instruction
in the next bit of the memory. (click) Decode. The CPU decodes the instruction. This time, it’s ADD,
and the address is 7. So we’ll be adding what’s at address 7
into what is already in the accumulator. (click) Execute. The CPU executes the instruction.
We add the value at address 7. In this case,
it’s the value 1. 1 + 1 is 2. (click) Fetch. From the next memory location, number 2. (click) Decode. An instruction to STORE the value in the accumulator
into RAM, at address 6. (click) Execute. Now, notice that we are overwriting what’s
already there, so address 6 now has 2 in it,
instead of 1. (click) Fetch. A new instruction: JUMP. With a jump, the next address we fetch from is the one
in this instruction. (click) Decode. So we’re going to jump to
address number 1. (click) Execute. The Program Counter is now back at 1. The ability to jump, to loop, and to build
instructions recursively is one of the foundations of computer science.
So: we’re back up there. (click) Fetch from location 1. (click) Decode. It’s the ADD instruction again. (click) Execute. Our accumulator still contains the values
from before, so: 2 + 1=3. (click) Fetch. (click) Decode. STORE again. (click) Execute. Storing it into location number 6. (click) Fetch. (click) Decode. (click) Execute. And we jump again. (click) Fetch. (click) Decode. (click) Execute.
(click) Fetch. (click) Decode. (click) Execute. (continues clicking) We’re in a loop,
and we’re counting upwards by one on every sixth clock cycle.
(stops clicking) Our program, with these simple instructions,
doesn’t have a halt command, or any way to interrupt it, so it will just keep incrementing
that value by one (many fast clicks) until the number becomes so large it can
no longer be held by the memory address. How it breaks then… well, that’s a whole
other video. (stops clicking) And my fingers are tired. This is a very fiddly way to program a computer. In theory, it can be
but at this level, these instructions are just encoded
in raw binary data, which is basically unreadable for humans. So we can convert that base 2 binary
to base 16, hexadecimal, at that level we call it machine code. The next step up from that is a symbolic language
called Assembly, which is a bit more readable, but it’s still close to working at that
bare metal. The original “Prince of Persia” game was completely
programmed in assembly. That is almost unbelievable to me: painstakingly figuring out each pixel of animation
and encoding it into something that the computer almost understands directly. Programming like that is complex, and hard, and prone to the sort of human error that
introduces massive security problems. It is difficult to code and difficult to debug. So rather than dealing with the messiness, or, well, the pristine logic of machine code, higher-level languages were developed as an
intermediary step. Those languages handle all of that memory
reading and writing for us, so all we need to focus on is
what we want the computer to do. So, here’s my code: just the same instructions,
phrased a little bit differently, phrased for humans to be able
to read. I specify a variable, X. I then write a function
that loops forever, and each passing through that loop
I increment X by 1. Once I’ve written that code, I then pass it
to a compiler, which turns it into that
original machine code for me. So when I run the program, it’s loaded into the computer’s memory,
and executed. If I want to run it on a completely different
type of computer, a Mac instead of a PC, I can compile it for that CPU instead. But this still doesn’t answer the question
of how the computer is doing something as complex as
decompressing and displaying this video. The answer to that is: speed. At the speed I was clicking,
at the end there, we were executing one instruction every couple
of seconds on one thread, one bit of the system. A modern CPU executes billions of instructions
per second – gigahertz – on multiple threads. But at the heart of your PC, or your phone, there is still just a ticking clock and
a fetch-execute cycle. I’ve used a password manager for years, and if you’re techie enough to reach the
end of this video, you should too. And I’m not just saying that because this video is
sponsored by Dashlane, a password manager, and if you go to dashlane.com/tomscott, you can get
a free 30-day trial of their premium version. Why should you use Dashlane? Well, first,
reusing passwords is a terrible idea. If you’re like me a few years back, then you’re reusing very similar passwords
that have a few letters changed, or have the site’s name stuck somewhere in them. It’s not great. One data breach at one of those sites, and it’d be time to start worrying. These days, Dashlane sits in my browser,
and when I want to log in somewhere, I unlock Dashlane with the single
password that I have to remember, and it autofills it for me. Dashlane also stores and autofills credit cards and
address information across your devices, and it’s got a VPN to encrypt your traffic on public wifi networks if you want to. If you are the kind of person who can remember 20-character unique symbol-filled passwords
for dozens of different sites, congratulations. But if you’re not superhuman,
then your choice is basically: use insecure passwords or
use a password manager. Now, you could use post-it notes on your
monitor as a password manager… or you could use Dashlane, which generates, stores, and autofills
long, secure, different passwords for every site. I don’t have to try and type in a 20-character password filled with symbols on my phone any more. I pull up Dashlane instead. Everything just works, synchronised on all my devices, across Windows, Mac, iPhone, Android,
all automatically. It plugs into Chrome, Firefox, Edge,
Safari, Opera, even Internet Explorer. And despite the fact that it’s all
synchronised in the cloud, Dashlane themselves don’t know what
those passwords are and based on their security architecture,
can never find them out. I’ll explain that next time. So: dashlane.com/tomscott for a 30-day
free trial of Dashlane Premium, which includes unlimited password storage and sync. And if you like it, you can use the code
“tomscott” for 10% off.

100 thoughts on “What’s Your Computer Actually Doing?

  • Tom Scott Post author

    And away we go with another season of three computer-science videos! A whole team made this happen: pull down the description for all the details! And thanks to Dashlane for sponsoring: you can find more about them at https://www.dashlane.com/tomscott

  • Andy Morales Post author

    This is what your computer is actually doing: Guna Ganga

  • ULOIRAR Post author

    6:14 so you format your braces that way? I believed in you Tom, I believed in you.

  • Figment HF Post author

    I aM stOoPiD 🙁

  • Mormodes Post author

    My eyes kept trying to focus the background.

  • Thang Ta Post author

    I think you can explain to us about how to peel a banana and we'd still be interested because it'll sound fancy and cool.

  • UnsaltedReconPlane Post author

    Every snap. A computer is gone reduced to atoms.

  • Skain Post author




  • Liam Bellingham Post author

    Press the "5" key then the "8" key. You're welcome

  • ghost name Post author

    M O R E C O N F F E T T I H E R E W E G O !!!

  • Robert Feranec Post author

    Love the explanation! I remember the times when we HAD to understand all this to be able to do magic with our computers.

  • Cyber One Post author

    And how do these counters, memories, regs, ram and that stuff work?

    Flip flops cough cough
    (+ ram has several types)

  • Krzysztof Piotrowski Post author

    Look what gem I found:
    Tom in 2003 episode of Treasure Hunt

  • David Pruitt Post author

    Missing an important fiddly bit known as conditional execution, which is what makes a computer so much more powerful than an oversized calculator.

  • BIG Dave Post author

    quickly closes chrome

  • onokje Post author

    Omg I never knew POP was written in assembly. That is seriously hardcore.

  • Yasser Arguelles Post author

    It's funny we call it random access memory, because that's one of the things it's not too good at. It's not very cache money

  • Serpentine Sausage Post author

    Britbong spelling is hilarious.

  • CJ Ware LRPS aka TheCreativeGeek Post author

    Computers are amazing things

  • Michael Pohoreski Post author

    The only ones who say programming assembly is hard are those who lack experience & skill. Like mastering any skill it becomes trivial with practice.

  • Pro Odermonicon Post author

    I think I found a typo:
    "Programme counter"

  • James Davis Post author

    If the fetch stage increments PC before retrieving the instruction, I think the instruction at address 3 should be JUMP 0.

    You could have it so that wasn't the case, but you'd have to have some extra bit of state to remember if the last instruction was a JUMP

  • Ic0n Post author

    Fetch, decode, execute. Just how i watch my porn…

  • Александр Коротецкий Post author

    In this video RAM architecture was "Von Neumann's". This means that instructions and data are not separated and can be ordered in memory as they want. The other architecture is called "Harvard's", in this one data IS separated from instructions.

  • Dab-a-tron Post author

    many beep boops very fast.

  • Tanmay Nemade Post author

    Person – CPU's working is so easy
    Pipelining – hold my data paths

  • Medium D Speaks Post author

    I wish I understood what was going on here, Tom

  • Daniel Holm Post author

    Random symbols make the passwords hard for us to remember. It doesn't make it harder for a computer to crack. Better to have a longer password than a short one, regardless of the "complexity" involved. Make up a sentence that is 40+ characters long, and it's virtually crack-proof. Then alter that sentence depending on the website, and you've got passwords no one can guess, that no one can crack, and that you can remember easily. I don't see the need for one of these services.

  • My Username is Pointlessly Long and Intimidating Post author


  • Balamurugan K Post author

    Where to learn these things source or something suggestions?

  • MrGallagher Post author

    So how does a modern processor compute billions of instructions a second? That's still mindboggling to me. (Not a rhetorical question: I'm genuinely impressed and baffled by such a high number of computations in such a limited amount of time.)

  • Peter Marsh Post author

    Great video as usual but a couple of nitpicks: I was always taught that the whole cycle happened every tick of the clock? Also you used the wrong spelling of programme.

  • Mark Paul Cards Post author

    Rollercoaster Tycoon was written in ASM (99%) and C (1%) also

  • mguarin912 Post author

    Jesus…that snap would make Pavlov’s dogs learn Calculus.

    Great video!

  • Vinney Sigler Post author

    Gamers be like:
    F0rTniTe 60FpS

    Computer Technician:
    Fetch, Decode, Execute.

  • thoughtlesskills Post author

    Background takes away from the red shirt, don't like it.

  • DasEmmiYogurt Post author

    I knew this already on a deeper level but I have to say this was the simplest explanation of a CPU cycle I've ever heard. Great job on that one. If people want a bit more details then search for The Computer Science crash course by PBS on youtube, still superficial but very informative and it changes the view of computers in general.

  • 『ΔIMΔN LR』 Post author

    Imagine hearing 4.6 billion snaps (4.6 Ghz) per second produced by our pc

  • Visionery1 Post author

    Finally I have the explanation why I opted for Mechanical Engineering… something I can touch. 🙂

  • Mush Mello Post author

    „The answer is Speed“
    Tom Scott, 2019

  • Stephan Post author

    Such a high quality video! I love how understandable you explain all that stuff

  • Lue 01 Post author

    Dislike for suggesting a CLOSED SOURCE password manager….

    Please use Bitwarden or Keepass people

  • Karl Lavender Post author

    222 people hate clocks.

  • D . D Post author

    My computer is spying on me

  • Daniel Dulu Post author

    And people think machine awareness is possible, think about it because your computer cannot. AI is based on an unimaginable number of paths and decisions that can be made based on instructions that humans set out.

  • IFireseekerI Post author

    I can assure you my computer isn't doing half of these things, or at least not properly anymore…

  • Logan_Playz Gamez Post author

    Are you filming at that place in Cambridge?? I went there on a school trip

  • aijec Post author

    Wow thanks I didn't understand a letter of that

  • Remidemmi96 Post author

    I just learnd tom seems to not write his opening parentheses on a new line and I am unsubscribing this very moment because of it.

  • Michael Bernhardt Post author

    Fetch, decode, execute. Fetch, decode, execute……. —> an iPod, a phone, an Internet communicator……
    That just came to my mind. But really understandable explanation of a simple computer. Thanks Tom.

  • Gydo194 Post author

    come on Tom, you should really have used "x++" instead of "x = x + 1"! 😉

  • Donald Trump Post author

    I hate 2 ads.

  • Lucas Ziolkowski Post author

    5:02 D1 not D7

  • Chris Walsh Post author

    Glad to see you back at the museum of computing history again Tom. I love the scaled up working computer in the background 🙂

  • peter müller Post author

    6:10 to display how much easier languages make things you could have just written "while(true) {x++};" Does the same, and is easier to read for people who have no idea of code, to whom your code probably looks more confusing as it contains more extra instructions

  • I can smell u Post author

    It has millions of tiny bees doing math for you

  • DLC Spider Post author

    Just for comparison, how fast modern computers really are: the time between two finger snips is shorter than the time the light from your screen needs to reach your eyes.

  • Petar Milic Post author

    I'm guessing the interrupt video is coming next then?

  • Le Artiste Post author

    Idk browsing for anime tiddies propably

  • TechMantra Post author

    If you take apart your phone or PC, your mum will kill you.

  • C M Post author

    A Mac is a PC!

  • Jack Gronenthal Post author

    And there’s my freshman year Computer Eng degree

  • 233kosta Post author

    Having just finished watching Ben Eater's breadboard computer build, this is a nice abstraction to add to the detailed electronics. Thank you for putting it together!

  • PowCrashBang Post author

    This must be the worst jazz on YouTube

  • GamerTurtle5 Post author

    I love this series!

  • Bri B Post author

    Already lots of comments so not sure if it has been covered. What happens to dashlane if you have no internet and worse still what if dashlane has a problem and goes offline?

  • Bobby Rank Post author

    A bit off topic, but could you do a video on the broomway, Essex.
    I'd love to see you sharing its history.

  • Lockirby2 Post author

    That ad is also basically a PSA.

  • Nulono Post author

    Doesn't the code you show differ from the base code because it starts at 1 instead of 0?

  • Kenny Brunton Post author

    Assembler programmer here. Probably not many of us left now. Waste my time building mobile phone apps and keeping up with Apple tantrums these days. Android is okay though.

  • Dennis el Azul Post author

    I thaught this using a simulator, but this video will be useful in the next scholar year for my class. Thank you!

  • jin choung Post author

    this is one of the fundamental questions that i had when i started learning about computers – how… EXACTLY… does manipulating bits with logic actually draw something to the screen.

    i think you can continue with on with this series by continuing to break that down. so right now, you say that the reason a computer can do things like play games and videos is speed… but that answer is kind of an abstraction too.

    you can break it down further:

    – how does jump or add translate into ands and ors
    – trace sequence of events from fetch/decode/execute to one pixel getting drawn to screen, or one sound being played, etc…

    great video!

  • Frustrated programmer Post author

    I know you are sponsored… but KeePass is better.
    It's an application you install and it encrypts your passwords into a local database. So it's never online and its 100% free! I've used it for years! Very handy and 0 risk data leaks cuz data never once leaves your local machine!

  • NorthernDruid Post author

    nice touch to swap your position to the other side of the screen for the sponsorship.

  • Brendan Keyport Post author

    where is this device that Tom Scott's sitting in front of?

  • A Google User Post author

    Very nice explanation! My informatics teacher at school actually wrote a virtual machine (for DOS) with it's own simple assembler language and some simulated IO to display text that allowed us students to step through the code and see what actually happens on the CPU. Damn, my informatics teacher was awesome! I owe him a great debt to this day!

  • brandon mckamey Post author

    You should do a video about Oak Ridge Tennessee

  • Ruqyah Services Post author

    You should make a 'Part 2' to show us viewers how you treated the blisters on your fingers as a result of all that clicking…

  • YouReyKarr Post author

    Your description of compiling is off. You say that if you want to move your program to a different OS you can just compile for that cpu, however you can run macOS, Windows 10 and Ubuntu all on a single processor and they won't be able to compile and execute the same code (depending on the high level language)

  • Clive Mattinson Post author

    Err, I'm taking a wild guess here……….COMPUTING? roll eyes

  • Alex Banks Post author

    If you really can explain to me the architecture behind why a password manager doesn't know my passwords then I may just concede and sign up so fair enough

  • aullik Post author

    well a pipeline is not really a fetch execute cycle. but close enough XD

  • skad dkas Post author

    my brain hurts

  • Free Love and Food Stamps Post author

    I've been an assembly programmer for years. Why am I watching this?

    Good explanation, most peoples heads tilt backwards when I try to explain assembly.

  • StigDesign1 Post author

    Awesome video well explaned and showed how it worked 😀

  • stupendous Post author

    tom snapping his fingers for 9 minutes straight

  • JH3Y50N Post author

    Are you from?

  • Oden Petersen Post author

    I actually need this for my test next week. Thanks Tom!

  • Rj Pena Post author

    Its amazing how your are managing both a quality and semi quantity channel!

  • なす Post author

    Fetch SNAP Decode SNAP Execute


  • Lizzam Abdul Latiff Post author

    how many lives are there on earth if each time Tom snaps his fingers, 50% of the living things are dusted (note that Thanos does not consider floras as living things, just fauna, same applies to this question.)

  • 607 Post author

    That was a long ad. 😛

  • Francis Post author

    Excellent video. Took me back to my Computer Science degree days!

  • JimPlaysGames Post author

    Okay, but what if Dashlane gets hacked? Doesn't this just create a single point of failure and a very juicy target for hackers?

  • Plasmaboo Post author

    If you're techie enough to use a password manager, you're techie enough to know that trusting a commercial company to keep your passwords safe against things like the law and large sums of money is insanity, and that you should not use any kind of password manager that isn't at the very least open source.
    That means, not using something like dashlane or lastpass for example. The most trusted open source option would be KeePassXC.

  • ceputza Post author

    Stop snapping. It's annoying.

  • Serge Girard Post author

    Good video. Regarding your sponsor, though, I consider the idea of concentrating all your passwords into one online area to be one of the worst anyone ever had. Of course, if such a location was 100 % hacker proof, I would be wrong. But we know that no program is that secure. So, I don’t think I will ever entrust all my passwords to any single program or website or any such thing.

  • Andy Roid Post author

    Dude, is there anything you do not know everything 'bout?

  • Alexander Sandholdt Post author

    Everybody: x += 1;

    Tom: x = x + 1;

  • Abdalrahim Abdullah Post author

    After watching this video,
    You know, I'm something of a computer scientist myself.

Leave a Reply

Your email address will not be published. Required fields are marked *