Nand2Tetris Unit 0 Introduction

来自iCenter Wiki
跳转至: 导航搜索

Introduction

S:Hello, and welcome to Nand to Tetris.My name is Shimon Schocken, and I'm a Professor of Computer Science at IDC Herzliya and Visiting Professor at the Hebrew University of Jerusalem.

N:Hi, I'm Noam Nisan, a Professor of Computer Science at the Hebrew University of Jerusalem, and a researcher at Microsoft. Together we'll teach you this course.

S:And and the first thing that we're going to want to do in this unit is to give you the overall picture of what this course is all about. Well, in this course we're going to build a complete general purpose working computer from the ground up. Hardware and software. And, we're going to divide this huge enterprise into two separate courses. In the first course, which is going to be seven weeks long, this course we're going to build the hardware of the computer. And in the second course that will be offered, later, we're going to do complete the picture and build the software hierarchy that sits on top of the computer that you will build in the first course. So that's what we're going to do in the next seven weeks. We're going to focus on building the hardware of the computer, which we call heck. So it's going to be a great journey consisting of seven weeks, six projects, one computer and zero prerequisite knowledge. We assume no knowledge whatsoever in computer science or engineering. Everything will be given to you in the course itself. So this has been our first unit in Nand to Tetris and coming up is the road ahead in more detailed description what we're going to do in this course.

文件:Nand to Tetris- the big picture.png

The Road Ahead

We're going to start this course by describing the main mental tool that computer science uses all the time that we're going to use in this course and in fact the main mental tool that will allow us to design a extremely complicated artifact step by step. Many of you have probably taken a programming course. Many of you may have not, but mainly you have. Usually, in such a course, the fir, in the first class, in the first lesson, you start looking at the very, very simple program, sometimes called Hello World. And this is a program that just prints Hello World on the screen. Usually, you start discussing the various fluff. Eh, around the commands, basically stating, oh, here is the program, and this is how it's supposed to be written. You talk about various commands, eh, in the program. For example, the 4th line, or the 5th line, the, in what you see in front of you basically tells the computer to print a string "Hello World!" on the screen, and that's really what the program does. And you discuss all that things. And that's how you start a programming course, a programming 101 course. Now when you think about that that's very problematic. There are a lot of things that are under the hood here. First of all there's this amazing thing. What you see is the program with just a bunch of letters. So for example if you have the p letter, this is a letter p. It's not doing, doing anything, it's just a letter. And in fact we know that in computers the letter p is represented by a number. So we have the number 112, and then you have a number 114 for r, and so on. And somehow these letters are supposed to do something, how does that happen? Well, you are told something about compiler that translated to a different language. And the other language, a computer hardware can execute, but how does that even work? All that is swept under the rug when you start introduction to computer science or to programming. Similarly, if you look at even the simplest programs, the simplest command, for example, print "Hello World". How are you supposed to do that? Printing Hello World on the screen actually involves setting a bunch of pixels on your screen to be more lighter or darker. And it's a lot of pixels and you have to actually the pixels that are lighter in a very special order to somehow represent the letter H and then the letter E. How is that all, all, all that happened that's an extremely complicated thing and yet you just use it. And that is also swept under the rug. Again you're told about standard libraries and operating systems that do all that for you. But, you don't really worry about them. Why I don't we have to worry about them? The main secret of computer science is the fact that you really don't have to worry about them. You can really start and do programming 101, as many students have done throughout the years, without worrying about all these very basic questions. How do that happen? How come you don't need to worry about how? Because, it's enough to worry about the what. It's enough to use, what the programming language is supposed to do. And you don't need to worry about what happens behind it. Because you're only using it. You're not now actually trying to duplicate it.

The how of something is called implementation. How do you actually make it happen. That's called to implement it. The what. It's called the Abstraction. That is if you sell the computer languages of both to do such and such, you don't need to worry about how it is done. But the such and such, the exact specification of the such and such, that's the abstraction that we have that's the interface that you get to work with, and you only need to worry about that when you actually program. When you are taught, In programming 101, that you actually can run that program. The whole point is that you only need to worry about the abstraction. That when you write that command, it's supposed to write hello world on the screen, and the whole point is that you don't need to worry about how that is done. It's enough to know what it does. This is not the bug in the way that we teach programming languages, it's actually the main point of programming languages. Don't worry about the rest; just worry about what it's supposed to do and trust that someone else worried about the how. So you may worry here, is this a scam? So if no one worries about how something is done only people are only enjoying the what's the nice things that are done. How is it ever going to be implemented? Who is going to worry about the how? Well, it could be someone else which is an always nice to know that someone else can do that. It could be you, later or earlier. If its later you don't need to worry about it now which is very nice because now you can focus on the task at hand which is using the com programming language. Even if it was you earlier that you already implemented the programming language in the past this allows you to forget allows you forget all the details all the works that you put into actually implementing it and just remember what Is the thing that you did. And that's the most, most potent tool of computer science.That, once we can separate concerns. When we can separate, we can forget a lot of details about implementation.And only remember a very clean, what? Interface, Description of what is done there. Then you get this mental, saving, of not having to have everything in your mind in the same time. You can repeat that many times in many different multiple layers of abstraction, one above the other.

So, for example, suppose we have already built the blue stage box. We can forget its implementation. Worry only about its interface. When we try to implement a green box above it. Once we've finished with the green box we can again we can forget its implementation,worry about only the interface when we implement the yellow-orange box above it. When we finish that we can forget again the implementation when we try to implement the purple box above the interface of the orange box. This way we have multiple stages, each one of them very simple. And yet at the end we get the fantastically complex artifact composed of many simple stages. This is exactly what we'll do in this course. Here is a high level description of the different abstraction layers we have in this course. We start with very [INAUDIBLE] Simple gates. We'll build more complicated chips from them and from them, we'll build even higher, more complicated chips like a CPU. And then, we put them into a computer and that continues as a software layer that we'll cover in part two of the course, where we build more and more complex software, software artifacts above these hardware artifacts.

Every week we will worry about a single level of abstraction. We take the lower level as given. We only remember what it does, we forget how we did it. We implement the higher level of abstractions and the next level of abstraction. We test that it works, And then, presto, we finished the week. We can move to the next week where we already know that this level works very well. So, the lower level, we can take as given in the next week because we just finished implementing it. The next level we are going to actually guide you give you very explicit guidance how you're going to implement the next level of abstraction given the fact that you already have the previous time. Then we also give you a testing suite that allows you to really test the, what you did this week works so that can be sure that next week everything will keep on functioning. So by the end of the course, what have we achieved? By the end of the course, after a few weeks of actually a, every week building upon the previous layer, we get a complete functioning computer. A computer that starts with very basic building blocks, called Nand gates, which are very, very simple logic gates. And ending with a computer that can run almost any program,. For example the tetris that gives this course its name. In the process of doing it you've gained a lot of very important computer science tools. First of all, you've gained the experience of working with abstractions. You've gained that if, in experience of working with the main, working towards the computer science at every point in time forgetting about what you don't need to remember about the how and working about the ext level of abstraction. This is the main thing we always do with programmers, and you've experienced it. You also, by the way, once you've did all the different steps, you learned at every step what you need. And the different steps in building a computer are the real, the interesting pieces of information you need to know. You need to understand in order to understand how a computer is actually constructed. At the end of the day, you sort of now have a complete understanding. You have built a complete functioning computer, you understand all the levels. So finally, the myth of how a computer works is no longer mystical. You understand it.

All this accomplishment, is going to be, is going to happen in 14 weeks. And in two parts in the first part of the course which is what we currently have on Corsera which is going to last seven weeks we're going to build the whole hardware platform of a computer we're going to start with a very simple logic command gate and we're going to create a computer that can run assembly machine programs. And this is what you do in the first, in the first part of the course, seven weeks, seven different steps, each step very simple. And you get the working hardware platform. In the second part of the course, which is going to be called, not surprisingly, from Nand to Tetris part two, we're going to start with the same hack computer which was built in the first part of the course,. And continue adding the software hierarchy that will allow us to actually run any type of application that we write in any, in a high level programming language, for example an application like Tetris, that gives this course it's name, but also any other type of application that you may want to write. What we're going to do in the next two unit is explain a little bit more, talk a little bit more about the road map ahead which tells us first of all what are we going to do in this course in the hard work part. What are the main steps that we're going to do. And then also what are the main steps that are going to be done in the second part. And after that, in the next week we'll actually start doing, going step-by-step.

From Nand to Hack

In this previous unit, Norm gave you an overall description of the Nand to Tetris journey. In this unit, we're going to focus on what we're going to do in this course, which is building a computer called Hack. So, here's the computer, in a very broad description, or sort of a diagram that captures only, some of its very main elements. It's going to have ROM, CPU, RAM and many other chips. And once we build this computer, we're going to connect it to a standard keyboard, and to a display unit. And at this point, you can start executing programs and enjoy the computer that you actually built. Which kind of programs? Well, anything that comes to your mind. You can write a program that plays Pong or a program that plays Space Invaders or Sokoban or, of course, Tetris. And these are actually examples of programs that were previously written by students. Who took this course. So, here's the general picture of this course and I'm basically repeating things that I know I've said before. We start with some general idea of the program that we want to write. We write the program, we compile it, we translate it further into machine language, we load the code into our computer. The computer is going to use all sorts of all sorts of chips that we built. Which are based on elementary logic gates and the whole thing ends up with the hardware itself. So basically what we did is we built a software hierarchy that sits on top of some hardware platform. And as Norm explained, we decided to split this enterprise into two different parts. The first part is called nand to Tetris part I and the second one which will be offered later is called nand to Tetris part II. And, in this particular course, we're going to focus on the hardware only, beginning at the very low level of the hardware itself, of electronics and and logic gates. And we're going to do it bottom up. So here we are at the very low level of of everything in, in applied computer science. And this actually is not computer science. This is electrical engineering and solid state physics, and so on. And all sorts of things that neither Norm and I understand much about. And therefore, we're going to obstruct the way this hardware and focus instead on the most elementary logic gate that we can think of, which is called Nand. You know, Nand is something that I can describe in ten seconds and I will do it in one of the following units, but for now. Let us assume that it's simply a basic, logic gate. We take this Nand gate, and from it, using a certain art called combinational logic, we're going to build a whole set of elementary logic gates like AND or Xor and so on. Then we'll take these gates and from them we are going to use both. Combinational logic and sequential logic, which is a different out of design, which takes into consideration times, and, and time and clocks, and from it we are going to build things like registers and RAM units, and and CPU. And then, we'll take this chip set that we built, and we'll design from it a full blown computer architecture called Hack. Now in order to write programs that can execute on this, on this machine and do it in a convenient way, we're going to also introduce an assembler into the picture and we're going to develop also an assembler for the Hack machine language. Now I've introduced all sorts of concepts that may sound very unfamiliar. Don't worry about it. Everything will be explained as the course progresses. Now, many of you are probably wondering, how are we going to actually build all these chips? Well, as it turns out, hardware engineers today don't do anything with their bare hands. They develop computers using computers. And in particular they use something called hardware simulator to design and test and debug the hardware that they want to build. And that's exactly what you will do also in this course. What we see here is a screenshot of our hardware simulator. A piece of software that you're going to download freely from our website. And the you're going to install it on your computer and you will do all the projects in this course using your computer and software that we will supply. So let us give you an example of how we are going to actually do it. Here's an example of Xor chip, which is one out of about 30 different chips that we're going to build in this course. And what you see here is an obstructed description of how Xor operates. So basically you're going to take this obstruction, think about it and. Along with all sorts of tips and guidance that we're going to provide. We'll come up with some logic diagram that enables you to build Xor using lower level gates, that you built before. Then you will take this diagram, and specify it using a language that we will teach you, which is called hardware description language. The result will be something called HDL program. You will take this HDL program. You will combine it with some test scripts that we that we will provide. And then you will debug, test, and complete your HDL program, using the hardware simulator that I described before. So that's what we're allowed to do with every one of the chips that we're going to build in this course. And the result is going to be the HAT computer. Now we're going to separate this journey into six different projects. So let me say a few words about every one of them. In the first week, we're going to build some elementary logic gates. 15 gates all together. As you see here in the slide. In the second week, we're going to build an arithmetic logic unit, an ALU, which is the centerpiece of the CPU that we'll build later. In the third week, we're going to build memory systems, you know, starting with registers and going all the way up to RAM and ROM units. In the fifth week we're going to take all the chips that, that we built so far and use it to design an actual computer. In week 4, before we build the computer we will write some programs in the Hack machine language in order to get, in order to get the feeling of what this computer is going to do, and in the last week in the course, we're going to introduce an assembler for the Hack machine language, and actually develop it in two different ways. One for people who have background in programming,. And one for people who don't. So these are all the projects that you're going to work on in this course and the result of your effort is going to be the Hack computer, a general purpose computer that can run any program that comes to your mind, Tetris and you know, practically anything else. Now, I'm sure that many of you are wondering, what do I have to know in order to take this course. Well, the answer is, we assume no previous knowledge whatsoever, in computer science engineering, or mathematics. All the necessary knowledge that is required to build the computer and to take this course. Is going to be supplied in the course itself. This is a self-contained course. You're going to learn a lot in seven weeks of exciting projects. So, this has been the unit in which we describe the journey from Nand to the Hack computer, and in the next unit we're going to overview the journey from Hack computer to Tetris.

From Hack to Tetris

In the last unit, you heard about what we're going to do in this course in Part One of the course. Now I'm going to talk very shortly tell you what still remains for the second part of the course for Nand to Tetris Part Two that is not currently offered. Well, in the first part, in this course, you're going to start with the very simple Nand Gate, as you've heard. And you get all the way to a working computer system, on which you can run any program, for example, Tetris, that gives this course a name. So what remains? What are we going to do in the se, in the second part? Well, the question is really the kind of programming that one does on that computer. In the computers that we're going to finish building in this course, we're also going to build a computer language that you can run on it, but it's a very low level assembly, assembly language. If you look at the assembly language, it does not look nice, it's certainly not what you start using in programming 101 courses. It's a very low level language, very inconvenient. Most programmers, they really want to work with a high level language, something like this, the example, that is ver, very typical of what you see in an introduction to programming course. So, the kind of things that you have in such high level language includes a rich language, loops, data types, methods, abstractions, many things that do not appear in the assembly language that is the end of this course. Also there are very high, many high level operations, for example, math operations, for example, input and output operations that are primitive and are expected by any programmer that wants to write to print Hello World! And expect "Hello World!" to appear on the screen. And in fact, in the second part of the course where we'll deal with the software hierarchy, this is exactly what we're going to implement. We're going to present a high level language, called Jack. And we're going to write a compiler to it, for it, using several levels of extraction, of course, because that's a complicate thing- building a, a compiler. Similarly we're going to build a standard, li, library and in fact a mini operating system that gives you all the high level services that programmers expect. Once you have these two things, then you basically as. The say the starting point of an introduction to programming course because you have a high-level language that you can use normally. And now eh, this, hopefully, closes all the gap between the base, very basics of how computers are built all the way to how the programming language and operating system and standard library that you expect to get as introductory computer programmer. A, as we said, a part two of Nand to Tetris is not yet offered. We, we plan to offer it in future but if you cannot wait, it's already ready in the website and in the course book. In the next unit we just want to talk, we will tell you a little about the first project or actually the zeroest project. We just wants to make sure that you are up to date, you found the web site, you know how to submit the exercises for in Coursera and then once we're finished with that, the next week we actually start with building the computer.

Project 0 Overview

In this unit we're going to talk about what we have to do in project zero. And, actually, we don't have to do much. Project zero consists of two tasks. First of all, you have to download the Nand2Tetris software suite and put it on your computer. This will take something like two, three minutes. And then, you have to submit an HDL program through the Coursera website just to make sure that you know how to use the user interface and so on. That's it. So, let us talk about downloading the software. In order to do it, you go to the Nand2tetris website and you click software. This page will open up. And within this page you have to focus on this link. You click it, and then NAnd2Teris says zip file is going to be downloaded to your computer. You take this zip file, you extract it somewhere in your computer. We recommend that you do it in your desktop. And that's it. You're going to have a folder called Nand2Tetris. Let us take a look at this folder and see what's inside. Well, basically, this folder has two subfolders. One of them is called tools and the other one is called projects. In the tools folder, you will find a whole set of software tools that we are going to use both in this course and in the second course which is not yet offered. So, basically, we're going to use the first three tools, hardware simulator, CPU emulator and assembler in this course. And the remaining tools will be used in Nand2Tetris part two. If you look at the project subfolder, you will find thirteen projects in it, or fourteen projects, actually, including this one, project zero. And once again, these projects they're going to be split into two categories. And you can by and large ignore completely the second category. So, once again, we're going to talk about subset of all these resources and projects. And that's what we're going to focus on in part one. We decided to go ahead and give you everything for those of you who want to continue to do the second part of the course on their own. But once again, please ignore everything which is not mentioned in this slide. So, if you open this folder called zero, zero, zero, which is associated with project zero, you will find in it a single file named file.txt. And all you have to do in project zero is submit this file through the Coursera course website. And we want you to do it because we want to make sure that you know how to upload a file, and we want to make sure that we received it so that you will be ready to submit homework later on in the course. So, first of all, make sure that you've downloaded the course software suite to your computer and that you can access this file through the course structure, the Nand2Tetris that is two folders. And, once again, take this file, submit it, and you are done with project zero. So, that's the end of this unit. And moving along to the next unit, unit one, let's build a computer.