[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.00,0:00:06.62,Default,,0000,0000,0000,,All right. So it's such a beautiful spring\Nday, here, on campus. I'm gonna record Dialogue: 0,0:00:06.62,0:00:13.23,Default,,0000,0000,0000,,outside, here at Stamford campus. Just\Nkind of sunny, park like. So where college Dialogue: 0,0:00:13.23,0:00:18.46,Default,,0000,0000,0000,,students just come [inaudible]. So the\Ntopic for this section is: What is Dialogue: 0,0:00:18.46,0:00:23.33,Default,,0000,0000,0000,,software? What is code? How is it that\Nsomething runs on a computer. So when we Dialogue: 0,0:00:23.33,0:00:28.58,Default,,0000,0000,0000,,talked about hardware in the computer we\Ntalked about the cpu, that's the brains of Dialogue: 0,0:00:28.58,0:00:33.71,Default,,0000,0000,0000,,the thing. So the cpu's what actually does\Nrunning, and the cpu implements what is Dialogue: 0,0:00:33.71,0:00:38.65,Default,,0000,0000,0000,,called? Machine code instructions'. And\Nmachine code instructions are extremely Dialogue: 0,0:00:38.65,0:00:43.97,Default,,0000,0000,0000,,simple. One machine code instruction might\Nadd two numbers, another instruction might Dialogue: 0,0:00:43.97,0:00:48.78,Default,,0000,0000,0000,,compare two numbers to see which one is\Nbigger. So when. For code that we've seen, Dialogue: 0,0:00:48.78,0:00:52.94,Default,,0000,0000,0000,,so something like pixel set red dot ten.\NThat's much more complicated, than an Dialogue: 0,0:00:52.94,0:00:57.08,Default,,0000,0000,0000,,individual machine code instruction. So\Nthe way that's going to work, is that Dialogue: 0,0:00:57.24,0:01:01.52,Default,,0000,0000,0000,,pixel set red dot ten. Will ultimately\Nexpand to a series of maybe five or ten of Dialogue: 0,0:01:01.52,0:01:05.13,Default,,0000,0000,0000,,these very simple machine code\Ninstructions. Such that, when those ten Dialogue: 0,0:01:05.13,0:01:09.53,Default,,0000,0000,0000,,instructions are run, one after the other,\Nit sorta has the effect of setting the red Dialogue: 0,0:01:09.53,0:01:13.66,Default,,0000,0000,0000,,value of the pixel to ten. Alright, and\NI'll get into more detail later on about, Dialogue: 0,0:01:13.82,0:01:19.39,Default,,0000,0000,0000,,how that, how that expansion happens. So,\NI think a good first question for running Dialogue: 0,0:01:19.39,0:01:24.74,Default,,0000,0000,0000,,a program is, what is a program? So I'll\Nlook at the, the right hand side of this Dialogue: 0,0:01:24.74,0:01:29.45,Default,,0000,0000,0000,,diagram. So a program, and I'll, I'll sort\Nof use this as my running example, Dialogue: 0,0:01:29.63,0:01:34.76,Default,,0000,0000,0000,,Firefox. So a program is made actually of\Njust an enormous sequence of these very Dialogue: 0,0:01:34.76,0:01:39.52,Default,,0000,0000,0000,,simple machine code instructions. And so,\Nwhen Firefox is, is running on your Dialogue: 0,0:01:39.52,0:01:44.10,Default,,0000,0000,0000,,computer, that means somewhere in RAM,\Nthere's a block of these instructions. Dialogue: 0,0:01:44.29,0:01:48.93,Default,,0000,0000,0000,,Such that running them, has, you know,\Ndoes the things that Firefox does. So it Dialogue: 0,0:01:48.93,0:01:53.75,Default,,0000,0000,0000,,blinks the cursor, it takes url, draws,\Ngets web pages and all that sort of stuff. Dialogue: 0,0:01:53.94,0:01:58.48,Default,,0000,0000,0000,,So. The individual instructions are really\Ntrivial, right. Just add two numbers. So Dialogue: 0,0:01:58.48,0:02:02.53,Default,,0000,0000,0000,,how does it get from that to like blinking\Nthe cursor? And the best I can say is it's Dialogue: 0,0:02:02.53,0:02:06.02,Default,,0000,0000,0000,,maybe sort of like the relationship\Nbetween sand and sculpture. That each Dialogue: 0,0:02:06.02,0:02:09.98,Default,,0000,0000,0000,,instruction is like a grain of sand. Like\Nby itself it's meaningless and it kind of Dialogue: 0,0:02:09.98,0:02:13.98,Default,,0000,0000,0000,,looks like all the others. But if you put\Nthem together in just the right way, you Dialogue: 0,0:02:13.98,0:02:17.47,Default,,0000,0000,0000,,can build this complicated overall\Nstructure. And so that is the way that Dialogue: 0,0:02:17.47,0:02:21.68,Default,,0000,0000,0000,,Firefox is built out of these, this these\Nsimple instructions. So the way it works Dialogue: 0,0:02:21.68,0:02:25.84,Default,,0000,0000,0000,,is the CPU, over here on the left, runs\Nwhat is called a fetch execute cycle. And Dialogue: 0,0:02:25.84,0:02:30.14,Default,,0000,0000,0000,,all that means is that, the CPU will start\Noff, let's say here, with Instruction one, Dialogue: 0,0:02:30.14,0:02:34.10,Default,,0000,0000,0000,,and it'll load that instruction and run\Nit. Or sometimes we'll say it executes Dialogue: 0,0:02:34.10,0:02:37.69,Default,,0000,0000,0000,,that instruction. So, it, it adds the two\Nnumbers, or it does whatever the Dialogue: 0,0:02:37.69,0:02:41.64,Default,,0000,0000,0000,,instruction says. And when it, it's done\Nwith Instruction one, it just goes down Dialogue: 0,0:02:41.64,0:02:45.84,Default,,0000,0000,0000,,the list. It goes to Instruction two, and\Nit does that one. Instructions for you, it Dialogue: 0,0:02:45.84,0:02:50.50,Default,,0000,0000,0000,,does that one, it's only just ru-, it just\Nruns through the sequence. So, when we say Dialogue: 0,0:02:50.50,0:02:55.15,Default,,0000,0000,0000,,that a CPU operates at two gigahertz, two\Nbillion operations per second, it's these Dialogue: 0,0:02:55.15,0:03:00.11,Default,,0000,0000,0000,,little instructions that, that refers to.\NSo there are, there's obviously a, a big Dialogue: 0,0:03:00.11,0:03:05.20,Default,,0000,0000,0000,,variety of instructions. But I'm just\Ngonna point out a couple special types. So Dialogue: 0,0:03:05.20,0:03:10.48,Default,,0000,0000,0000,,one type of instruction has the effect of\Nchanging the order that the instruction. Dialogue: 0,0:03:10.48,0:03:15.27,Default,,0000,0000,0000,,Normally the CPU just runs down the list\Nand does them in order. But let?s say Dialogue: 0,0:03:15.27,0:03:20.36,Default,,0000,0000,0000,,instruction four maybe says, oh jump back\Nand start executing again at instruction Dialogue: 0,0:03:20.36,0:03:24.30,Default,,0000,0000,0000,,one. And so think about what the cpu's\Ngonna do. So it's gonna do instructions... Dialogue: 0,0:03:24.30,0:03:27.86,Default,,0000,0000,0000,,One, two, three, four. And then when it\Ngets to four, it'll sorta jump back, and Dialogue: 0,0:03:27.86,0:03:31.74,Default,,0000,0000,0000,,do instructions one, two, three again. And\Nthen one, two, three again, and again. You Dialogue: 0,0:03:31.74,0:03:35.01,Default,,0000,0000,0000,,can sorta see that's how loops are\Nimplemented. Just arranging the Dialogue: 0,0:03:35.01,0:03:38.80,Default,,0000,0000,0000,,instructions so that they'res some piece\Nof code we wanna do 500,000 times. Well, Dialogue: 0,0:03:38.80,0:03:42.73,Default,,0000,0000,0000,,you can set up an instruction to just loop\Nback and so, do those instructions again Dialogue: 0,0:03:42.73,0:03:47.41,Default,,0000,0000,0000,,and again. Another sort of instruction.\NOur [inaudible] idea is an instruction, Dialogue: 0,0:03:47.41,0:03:53.24,Default,,0000,0000,0000,,well, the same instruction two here, which\Ntests some condition and if the condition Dialogue: 0,0:03:53.24,0:03:58.85,Default,,0000,0000,0000,,is true maybe it skips ahead where\Ninstruction five would be here. So. That's Dialogue: 0,0:03:58.85,0:04:02.32,Default,,0000,0000,0000,,how if statements are implemented. You\Nhave an instruction that's gonna look at Dialogue: 0,0:04:02.32,0:04:05.65,Default,,0000,0000,0000,,some condition, and if it's, if the\Ncondition is true, it's gonna sort of tell Dialogue: 0,0:04:05.65,0:04:08.99,Default,,0000,0000,0000,,the CPU to go over here. And if it's\Nfalse, it'll go over to some other place. Dialogue: 0,0:04:09.12,0:04:12.86,Default,,0000,0000,0000,,So by arranging the instructions just so,\Nyou can get the effect of, something that Dialogue: 0,0:04:12.86,0:04:18.90,Default,,0000,0000,0000,,we, that, in our code, looks like an if\Nstatement. [sound]. Alrighty. So Well so Dialogue: 0,0:04:18.90,0:04:24.05,Default,,0000,0000,0000,,how, how does a program get running and\Nhow do we get to, how do we get to this Dialogue: 0,0:04:24.05,0:04:28.83,Default,,0000,0000,0000,,thing. So I would imagine you've got,\NFirefox on your flash drive, you know, the Dialogue: 0,0:04:28.83,0:04:33.44,Default,,0000,0000,0000,,file. So on your flash drive, or on your\Nhard drive. So here, I've stored, long Dialogue: 0,0:04:33.44,0:04:37.81,Default,,0000,0000,0000,,term, you know, persistent storage down\Nhere. And here's RAM and here's the CPU. Dialogue: 0,0:04:37.81,0:04:42.18,Default,,0000,0000,0000,,So when you've got Firefox on your hard\Ndrive. It's, it's a file, basically, and Dialogue: 0,0:04:42.18,0:04:46.43,Default,,0000,0000,0000,,here I, it's called Firefox exe, that's\Njust a windows convention, for, how to Dialogue: 0,0:04:46.43,0:04:50.67,Default,,0000,0000,0000,,name a file, which is a program, but it,\Nit helps keep things clearer so I'll Dialogue: 0,0:04:50.67,0:04:55.48,Default,,0000,0000,0000,,follow that. So firefox.exe, that file, it\Nhas a lot of bytes in it, and for the most Dialogue: 0,0:04:55.48,0:04:59.33,Default,,0000,0000,0000,,part, those bytes, are just the\Ninstructions, that make up the program, Dialogue: 0,0:04:59.33,0:05:03.72,Default,,0000,0000,0000,,plus some icons. [inaudible] and other\Nstuff. So what I want to think about is Dialogue: 0,0:05:03.72,0:05:08.16,Default,,0000,0000,0000,,well, what happens when you double click\NFirefox.exc? How does it start running? Dialogue: 0,0:05:08.16,0:05:12.95,Default,,0000,0000,0000,,And basically what happens is there's two\Nsteps. The first thing that happens is the Dialogue: 0,0:05:12.95,0:05:17.51,Default,,0000,0000,0000,,bytes for these instructions, at least\Nenough of the instructions to get started, Dialogue: 0,0:05:17.51,0:05:22.19,Default,,0000,0000,0000,,get copied up to RAM. So it just copies,\Nputs the instructions in RAM where the CPU Dialogue: 0,0:05:22.19,0:05:26.12,Default,,0000,0000,0000,,can get at them. And then step two, just\Ntell the CPU, 'Okay, well, here's Dialogue: 0,0:05:26.12,0:05:30.62,Default,,0000,0000,0000,,instruction one. Start executing here.'\NAnd so then the CPU just starts ripping Dialogue: 0,0:05:30.62,0:05:35.26,Default,,0000,0000,0000,,down the series of instructions and now\Nit's running Firefox. So I think this Dialogue: 0,0:05:35.26,0:05:40.19,Default,,0000,0000,0000,,leads to the question of like, well who do\Nthis right? How did, how did, who handles Dialogue: 0,0:05:40.19,0:05:45.34,Default,,0000,0000,0000,,the double click? Who gets Firefox\Nrunning? And so that's what an operating Dialogue: 0,0:05:45.34,0:05:50.73,Default,,0000,0000,0000,,system is. So the operating system is a\Nset of kind of supervisory and Dialogue: 0,0:05:50.73,0:05:56.72,Default,,0000,0000,0000,,administrative programs that sort of you\Nknow, organize, organize the whole system. Dialogue: 0,0:05:56.94,0:06:01.27,Default,,0000,0000,0000,,So, in particular, the operating system\Nmanages multiple programs, and starting Dialogue: 0,0:06:01.27,0:06:06.06,Default,,0000,0000,0000,,and, ending programs. So a modern computer\Ncan, run multiple programs at the same Dialogue: 0,0:06:06.06,0:06:10.73,Default,,0000,0000,0000,,time and so the operating system sorta\Nkeeps things organized. So it, it does the Dialogue: 0,0:06:10.73,0:06:15.07,Default,,0000,0000,0000,,initial startup of a program, giving it\Nsome RAM to use, and maybe giving it a Dialogue: 0,0:06:15.07,0:06:19.13,Default,,0000,0000,0000,,window to draw in. Also, operating systems\Ntry to keep programs isolated from each Dialogue: 0,0:06:19.13,0:06:22.86,Default,,0000,0000,0000,,other. So each program has its RAM, but it\Ncan't necessarily just go mess with the Dialogue: 0,0:06:22.86,0:06:26.60,Default,,0000,0000,0000,,RAM of some other program. So that helps\Nif a program has bugs. Hopefully, it'll Dialogue: 0,0:06:26.60,0:06:30.48,Default,,0000,0000,0000,,just mess up that program, but not mess up\Nsome other program that you're running. Or Dialogue: 0,0:06:30.48,0:06:34.31,Default,,0000,0000,0000,,maliciously, if I program was trying to do\Nsomething bad to some other program that, Dialogue: 0,0:06:34.45,0:06:38.08,Default,,0000,0000,0000,,the operating system tries to keep them\Nseparate. So, the operating system is Dialogue: 0,0:06:38.08,0:06:42.10,Default,,0000,0000,0000,,really the first thing that runs when your\Ncomputer starts up. So that's what's gonna Dialogue: 0,0:06:42.10,0:06:45.75,Default,,0000,0000,0000,,put up those first windows, and maybe show\Nyou what's on the hard drive. And then, Dialogue: 0,0:06:45.75,0:06:49.45,Default,,0000,0000,0000,,from thereafter, you can double click, or\Ndo other things, and the operating system Dialogue: 0,0:06:49.45,0:06:52.74,Default,,0000,0000,0000,,will start those programs for you. So\Nthat's really the, the thing you're Dialogue: 0,0:06:52.74,0:06:56.29,Default,,0000,0000,0000,,seeing, when you start up your laptop.\NDigital camera, it, you don't think of it Dialogue: 0,0:06:56.29,0:06:59.30,Default,,0000,0000,0000,,as a computer, necessarily, but it's\Nreally the same. When the digital camera Dialogue: 0,0:06:59.30,0:07:02.58,Default,,0000,0000,0000,,first starts up, there's probably a couple\Nprograms. There's maybe the program that Dialogue: 0,0:07:02.58,0:07:05.71,Default,,0000,0000,0000,,takes pictures, and the program that lets\Nyou look through the pictures you've Dialogue: 0,0:07:05.71,0:07:08.79,Default,,0000,0000,0000,,already taken. And so, when the camera\Nfirst starts out, there's a little bit of Dialogue: 0,0:07:08.79,0:07:11.92,Default,,0000,0000,0000,,administrative, sorta get, get the, the\Nprograms running to sort of show you the Dialogue: 0,0:07:11.92,0:07:17.47,Default,,0000,0000,0000,,interface, and then it just lets you go.\NAm. So just as a, a last thing, there's Dialogue: 0,0:07:17.47,0:07:21.34,Default,,0000,0000,0000,,sort of the, the, these, this terminology\Nboot and reboot, I always thought that was Dialogue: 0,0:07:21.34,0:07:25.08,Default,,0000,0000,0000,,kinda funny. Like, where does that come\Nfrom? And I-, it refers to the sort of Dialogue: 0,0:07:25.08,0:07:28.91,Default,,0000,0000,0000,,chicken egg problem of, like, well, when\Nthe computer first turns on, when it first Dialogue: 0,0:07:28.91,0:07:31.98,Default,,0000,0000,0000,,starts up, how does it. How does it get\Nitself organized? How does it start Dialogue: 0,0:07:31.98,0:07:36.06,Default,,0000,0000,0000,,running a program? And this terminology\Nactually comes from sort of an old joke, Dialogue: 0,0:07:36.06,0:07:40.15,Default,,0000,0000,0000,,about if you want to get over a fence,\Nwhat you could just do is reach down to Dialogue: 0,0:07:40.15,0:07:44.14,Default,,0000,0000,0000,,your bootstraps, and pull up, and just\Nlike lift yourself over the fence that Dialogue: 0,0:07:44.14,0:07:48.34,Default,,0000,0000,0000,,way. And it's obviously kind of absurd.\NBut it, it has the same quality of like, Dialogue: 0,0:07:48.34,0:07:52.27,Default,,0000,0000,0000,,well wait, what program does the computer\Nrun to enable the computer to run Dialogue: 0,0:07:52.27,0:07:57.26,Default,,0000,0000,0000,,programs. So it sort of a chicken and egg\Nproblem. So the way it works is that the Dialogue: 0,0:07:57.26,0:08:02.42,Default,,0000,0000,0000,,hardware, the, the CPU, has, when it\Nrecognizes that it has, it was turned off, Dialogue: 0,0:08:02.42,0:08:07.90,Default,,0000,0000,0000,,and that it has, it has just started up.\NAnd so there's a special tiny program that Dialogue: 0,0:08:07.90,0:08:13.20,Default,,0000,0000,0000,,is hardwired into the computer to run, at\Nthat moment. And that program can maybe Dialogue: 0,0:08:13.20,0:08:17.55,Default,,0000,0000,0000,,check, check what's hardware area, you\Nknow, do some basic early start-up stuff. Dialogue: 0,0:08:17.55,0:08:22.24,Default,,0000,0000,0000,,And then pretty much it looks around for a\Nhard disk or a flash drive or something Dialogue: 0,0:08:22.24,0:08:26.58,Default,,0000,0000,0000,,that contains an operating system on it.\NAnd then it can start that operating Dialogue: 0,0:08:26.58,0:08:31.16,Default,,0000,0000,0000,,system and then, then the computer can\Nstart up in that way. So that's why it's Dialogue: 0,0:08:31.16,0:08:35.90,Default,,0000,0000,0000,,called boot up. It refers to this old boot\Nstrap idea. And then that's what rebooting Dialogue: 0,0:08:35.90,0:08:40.47,Default,,0000,0000,0000,,is. So reboot means just to sort of, we\Nwant to get a clean slate so it's going to Dialogue: 0,0:08:40.47,0:08:44.32,Default,,0000,0000,0000,,shut down and start up fresh. All right.\NSo now you know.