Return to Video

Software I

  • 0:00 - 0:07
    All right. So it's such a beautiful spring
    day, here, on campus. I'm gonna record
  • 0:07 - 0:13
    outside, here at Stamford campus. Just
    kind of sunny, park like. So where college
  • 0:13 - 0:18
    students just come [inaudible]. So the
    topic for this section is: What is
  • 0:18 - 0:23
    software? What is code? How is it that
    something runs on a computer. So when we
  • 0:23 - 0:29
    talked about hardware in the computer we
    talked about the cpu, that's the brains of
  • 0:29 - 0:34
    the thing. So the cpu's what actually does
    running, and the cpu implements what is
  • 0:34 - 0:39
    called? Machine code instructions'. And
    machine code instructions are extremely
  • 0:39 - 0:44
    simple. One machine code instruction might
    add two numbers, another instruction might
  • 0:44 - 0:49
    compare two numbers to see which one is
    bigger. So when. For code that we've seen,
  • 0:49 - 0:53
    so something like pixel set red dot ten.
    That's much more complicated, than an
  • 0:53 - 0:57
    individual machine code instruction. So
    the way that's going to work, is that
  • 0:57 - 1:02
    pixel set red dot ten. Will ultimately
    expand to a series of maybe five or ten of
  • 1:02 - 1:05
    these very simple machine code
    instructions. Such that, when those ten
  • 1:05 - 1:10
    instructions are run, one after the other,
    it sorta has the effect of setting the red
  • 1:10 - 1:14
    value of the pixel to ten. Alright, and
    I'll get into more detail later on about,
  • 1:14 - 1:19
    how that, how that expansion happens. So,
    I think a good first question for running
  • 1:19 - 1:25
    a program is, what is a program? So I'll
    look at the, the right hand side of this
  • 1:25 - 1:29
    diagram. So a program, and I'll, I'll sort
    of use this as my running example,
  • 1:30 - 1:35
    Firefox. So a program is made actually of
    just an enormous sequence of these very
  • 1:35 - 1:40
    simple machine code instructions. And so,
    when Firefox is, is running on your
  • 1:40 - 1:44
    computer, that means somewhere in RAM,
    there's a block of these instructions.
  • 1:44 - 1:49
    Such that running them, has, you know,
    does the things that Firefox does. So it
  • 1:49 - 1:54
    blinks the cursor, it takes url, draws,
    gets web pages and all that sort of stuff.
  • 1:54 - 1:58
    So. The individual instructions are really
    trivial, right. Just add two numbers. So
  • 1:58 - 2:03
    how does it get from that to like blinking
    the cursor? And the best I can say is it's
  • 2:03 - 2:06
    maybe sort of like the relationship
    between sand and sculpture. That each
  • 2:06 - 2:10
    instruction is like a grain of sand. Like
    by itself it's meaningless and it kind of
  • 2:10 - 2:14
    looks like all the others. But if you put
    them together in just the right way, you
  • 2:14 - 2:17
    can build this complicated overall
    structure. And so that is the way that
  • 2:17 - 2:22
    Firefox is built out of these, this these
    simple instructions. So the way it works
  • 2:22 - 2:26
    is the CPU, over here on the left, runs
    what is called a fetch execute cycle. And
  • 2:26 - 2:30
    all that means is that, the CPU will start
    off, let's say here, with Instruction one,
  • 2:30 - 2:34
    and it'll load that instruction and run
    it. Or sometimes we'll say it executes
  • 2:34 - 2:38
    that instruction. So, it, it adds the two
    numbers, or it does whatever the
  • 2:38 - 2:42
    instruction says. And when it, it's done
    with Instruction one, it just goes down
  • 2:42 - 2:46
    the list. It goes to Instruction two, and
    it does that one. Instructions for you, it
  • 2:46 - 2:50
    does that one, it's only just ru-, it just
    runs through the sequence. So, when we say
  • 2:50 - 2:55
    that a CPU operates at two gigahertz, two
    billion operations per second, it's these
  • 2:55 - 3:00
    little instructions that, that refers to.
    So there are, there's obviously a, a big
  • 3:00 - 3:05
    variety of instructions. But I'm just
    gonna point out a couple special types. So
  • 3:05 - 3:10
    one type of instruction has the effect of
    changing the order that the instruction.
  • 3:10 - 3:15
    Normally the CPU just runs down the list
    and does them in order. But let?s say
  • 3:15 - 3:20
    instruction four maybe says, oh jump back
    and start executing again at instruction
  • 3:20 - 3:24
    one. And so think about what the cpu's
    gonna do. So it's gonna do instructions...
  • 3:24 - 3:28
    One, two, three, four. And then when it
    gets to four, it'll sorta jump back, and
  • 3:28 - 3:32
    do instructions one, two, three again. And
    then one, two, three again, and again. You
  • 3:32 - 3:35
    can sorta see that's how loops are
    implemented. Just arranging the
  • 3:35 - 3:39
    instructions so that they'res some piece
    of code we wanna do 500,000 times. Well,
  • 3:39 - 3:43
    you can set up an instruction to just loop
    back and so, do those instructions again
  • 3:43 - 3:47
    and again. Another sort of instruction.
    Our [inaudible] idea is an instruction,
  • 3:47 - 3:53
    well, the same instruction two here, which
    tests some condition and if the condition
  • 3:53 - 3:59
    is true maybe it skips ahead where
    instruction five would be here. So. That's
  • 3:59 - 4:02
    how if statements are implemented. You
    have an instruction that's gonna look at
  • 4:02 - 4:06
    some condition, and if it's, if the
    condition is true, it's gonna sort of tell
  • 4:06 - 4:09
    the CPU to go over here. And if it's
    false, it'll go over to some other place.
  • 4:09 - 4:13
    So by arranging the instructions just so,
    you can get the effect of, something that
  • 4:13 - 4:19
    we, that, in our code, looks like an if
    statement. [sound]. Alrighty. So Well so
  • 4:19 - 4:24
    how, how does a program get running and
    how do we get to, how do we get to this
  • 4:24 - 4:29
    thing. So I would imagine you've got,
    Firefox on your flash drive, you know, the
  • 4:29 - 4:33
    file. So on your flash drive, or on your
    hard drive. So here, I've stored, long
  • 4:33 - 4:38
    term, you know, persistent storage down
    here. And here's RAM and here's the CPU.
  • 4:38 - 4:42
    So when you've got Firefox on your hard
    drive. It's, it's a file, basically, and
  • 4:42 - 4:46
    here I, it's called Firefox exe, that's
    just a windows convention, for, how to
  • 4:46 - 4:51
    name a file, which is a program, but it,
    it helps keep things clearer so I'll
  • 4:51 - 4:55
    follow that. So firefox.exe, that file, it
    has a lot of bytes in it, and for the most
  • 4:55 - 4:59
    part, those bytes, are just the
    instructions, that make up the program,
  • 4:59 - 5:04
    plus some icons. [inaudible] and other
    stuff. So what I want to think about is
  • 5:04 - 5:08
    well, what happens when you double click
    Firefox.exc? How does it start running?
  • 5:08 - 5:13
    And basically what happens is there's two
    steps. The first thing that happens is the
  • 5:13 - 5:18
    bytes for these instructions, at least
    enough of the instructions to get started,
  • 5:18 - 5:22
    get copied up to RAM. So it just copies,
    puts the instructions in RAM where the CPU
  • 5:22 - 5:26
    can get at them. And then step two, just
    tell the CPU, 'Okay, well, here's
  • 5:26 - 5:31
    instruction one. Start executing here.'
    And so then the CPU just starts ripping
  • 5:31 - 5:35
    down the series of instructions and now
    it's running Firefox. So I think this
  • 5:35 - 5:40
    leads to the question of like, well who do
    this right? How did, how did, who handles
  • 5:40 - 5:45
    the double click? Who gets Firefox
    running? And so that's what an operating
  • 5:45 - 5:51
    system is. So the operating system is a
    set of kind of supervisory and
  • 5:51 - 5:57
    administrative programs that sort of you
    know, organize, organize the whole system.
  • 5:57 - 6:01
    So, in particular, the operating system
    manages multiple programs, and starting
  • 6:01 - 6:06
    and, ending programs. So a modern computer
    can, run multiple programs at the same
  • 6:06 - 6:11
    time and so the operating system sorta
    keeps things organized. So it, it does the
  • 6:11 - 6:15
    initial startup of a program, giving it
    some RAM to use, and maybe giving it a
  • 6:15 - 6:19
    window to draw in. Also, operating systems
    try to keep programs isolated from each
  • 6:19 - 6:23
    other. So each program has its RAM, but it
    can't necessarily just go mess with the
  • 6:23 - 6:27
    RAM of some other program. So that helps
    if a program has bugs. Hopefully, it'll
  • 6:27 - 6:30
    just mess up that program, but not mess up
    some other program that you're running. Or
  • 6:30 - 6:34
    maliciously, if I program was trying to do
    something bad to some other program that,
  • 6:34 - 6:38
    the operating system tries to keep them
    separate. So, the operating system is
  • 6:38 - 6:42
    really the first thing that runs when your
    computer starts up. So that's what's gonna
  • 6:42 - 6:46
    put up those first windows, and maybe show
    you what's on the hard drive. And then,
  • 6:46 - 6:49
    from thereafter, you can double click, or
    do other things, and the operating system
  • 6:49 - 6:53
    will start those programs for you. So
    that's really the, the thing you're
  • 6:53 - 6:56
    seeing, when you start up your laptop.
    Digital camera, it, you don't think of it
  • 6:56 - 6:59
    as a computer, necessarily, but it's
    really the same. When the digital camera
  • 6:59 - 7:03
    first starts up, there's probably a couple
    programs. There's maybe the program that
  • 7:03 - 7:06
    takes pictures, and the program that lets
    you look through the pictures you've
  • 7:06 - 7:09
    already taken. And so, when the camera
    first starts out, there's a little bit of
  • 7:09 - 7:12
    administrative, sorta get, get the, the
    programs running to sort of show you the
  • 7:12 - 7:17
    interface, and then it just lets you go.
    Am. So just as a, a last thing, there's
  • 7:17 - 7:21
    sort of the, the, these, this terminology
    boot and reboot, I always thought that was
  • 7:21 - 7:25
    kinda funny. Like, where does that come
    from? And I-, it refers to the sort of
  • 7:25 - 7:29
    chicken egg problem of, like, well, when
    the computer first turns on, when it first
  • 7:29 - 7:32
    starts up, how does it. How does it get
    itself organized? How does it start
  • 7:32 - 7:36
    running a program? And this terminology
    actually comes from sort of an old joke,
  • 7:36 - 7:40
    about if you want to get over a fence,
    what you could just do is reach down to
  • 7:40 - 7:44
    your bootstraps, and pull up, and just
    like lift yourself over the fence that
  • 7:44 - 7:48
    way. And it's obviously kind of absurd.
    But it, it has the same quality of like,
  • 7:48 - 7:52
    well wait, what program does the computer
    run to enable the computer to run
  • 7:52 - 7:57
    programs. So it sort of a chicken and egg
    problem. So the way it works is that the
  • 7:57 - 8:02
    hardware, the, the CPU, has, when it
    recognizes that it has, it was turned off,
  • 8:02 - 8:08
    and that it has, it has just started up.
    And so there's a special tiny program that
  • 8:08 - 8:13
    is hardwired into the computer to run, at
    that moment. And that program can maybe
  • 8:13 - 8:18
    check, check what's hardware area, you
    know, do some basic early start-up stuff.
  • 8:18 - 8:22
    And then pretty much it looks around for a
    hard disk or a flash drive or something
  • 8:22 - 8:27
    that contains an operating system on it.
    And then it can start that operating
  • 8:27 - 8:31
    system and then, then the computer can
    start up in that way. So that's why it's
  • 8:31 - 8:36
    called boot up. It refers to this old boot
    strap idea. And then that's what rebooting
  • 8:36 - 8:40
    is. So reboot means just to sort of, we
    want to get a clean slate so it's going to
  • 8:40 - 8:44
    shut down and start up fresh. All right.
    So now you know.
Title:
Software I
Video Language:
English
stanford-bot edited English subtitles for Software I
stanford-bot edited English subtitles for Software I
stanford-bot added a translation

English subtitles

Revisions