Introduction: From Nand to Tetris

Similar documents
Introduction: Hello, World Below

Course overview. Introduction to Computer Yung-Yu Chuang. with slides by Nisan & Schocken (

Course overview. Introduction to Computer Yung-Yu Chuang. with slides by Nisan & Schocken (

Course overview. Introduction to Computer Yung-Yu Chuang. with slides by Nisan & Schocken (

Virtual Machine. Part I: Stack Arithmetic. Building a Modern Computer From First Principles.

Assembler Human Thought

Virtual Machine Where we are at: Part I: Stack Arithmetic. Motivation. Compilation models. direct compilation:... 2-tier compilation:

Assembler. Building a Modern Computer From First Principles.

Virtual Machine. Part II: Program Control. Building a Modern Computer From First Principles.

Chapter 0: The grand Tour The Grand Tour 1. The true voyage of discovery consists not of going to new places, but of having a new pair of eyes.

Boolean Arithmetic. From Nand to Tetris Building a Modern Computer from First Principles. Chapter 2

Machine (Assembly) Language

Computer Architecture

Machine (Assembly) Language Human Thought

Motivation. Compiler. Our ultimate goal: Hack code. Jack code (example) Translate high-level programs into executable code. return; } } return

Compiler II: Code Generation Human Thought

Chapter 6: Assembler

Chapter 11: Compiler II: Code Generation

Chapter 6: The Assembler The Assembler Hack Assembly-to-Binary Translation Specification

Chapter 8: Virtual Machine II: Program Control

IWKS 3300: NAND to Tetris Spring John K. Bennett. Assembler

Compiler I: Syntax Analysis

Chapter 10: Compiler I: Syntax Analysis

Compiler I: Sytnax Analysis

Computer Architecture

STEVEN R. BAGLEY THE ASSEMBLER

Virtual Machine (Part II)

EP1200 Introduction to Computing Systems Engineering. Computer Architecture

Boolean Logic. From Nand to Tetris Building a Modern Computer from First Principles. Chapter 1

Sequential Logic. Building a Modern Computer From First Principles.

Chapter 9: High Level Language

Project 8: Virtual Machine Translator II

IWKS 2300/5300 Fall John K. Bennett. Machine Language

Computer Architecture

Boolean Arithmetic. Building a Modern Computer From First Principles.

Arithmetic Logic Unit (ALU)

High Level Language (Jack)

High-Level Language. Building a Modern Computer From First Principles.

Appendix A: Hardware Description Language (HDL) 1

Appendix A: Hardware Description Language (HDL) 1

High-Level Language. Where we are at: Some milestones in the evolution of programming languages. Programming languages

//converts a string to a non-negative number string2int(string s){

EP1200 Introduktion till datorsystemteknik Tentamen tisdagen den 3 juni 2014, till 18.00

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

Boolean logic. Boolean Algebra. Introduction to Computer Yung-Yu Chuang NOT AND NOT

Intermediate Code Generation

Project 6: Assembler

Foundation to Computer Systems Design. Indian Institute of Technology Madras. Professor V. Kamakoti. Department of Computer science and Engineering

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

CSE 582 Autumn 2002 Exam 11/26/02

7. The Virtual Machine II: Flow Control 1

10. The Compiler II: Code Generation 1

EMBEDDED SOPC DESIGN WITH NIOS II PROCESSOR AND VHDL EXAMPLES

Guidelines for Using LogicCircuit with the Nand2Tetris HDL Tool Suite John K. Bennett January 2019

Hardware Simulator Tutorial

1.00 Lecture 8. Using An Existing Class, cont.

High-Level Language. Where we are at:

IB Computer Science Topic.2-

1. Boolean algebra. [6] 2. Constructing a circuit. [4] 3. Number representation [4] 4. Adders [4] 5. ALU [2] 6. Software [4]

Project 5: Computer Architecture

CMPUT 101 with Solutions Quiz 2 (50 minutes) November 16, 2000

SaM. 1. Introduction. 2. Stack Machine

Virtual Machine (Part II)

Programming by Delegation

Sample Exam I PAC II ANSWERS

CSC180: Lecture 2. Wael Aboulsaadat.

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

Abstract Interpretation Continued

Where We Are. Quick History Lesson. Lecture 8: Combinational Verilog. Specifying Circuits. Last lecture: Minimization with K!maps

HW Simulator Tutorial

Computer Architecture

LCC 6310 The Computer as an Expressive Medium. Lecture 1

COSC 122 Computer Fluency. Computer Organization. Dr. Ramon Lawrence University of British Columbia Okanagan

CSE 403: Software Engineering, Spring courses.cs.washington.edu/courses/cse403/15sp/ UML Class Diagrams. Emina Torlak

Elements of Computing Systems, Nisan & Schocken, MIT Press. Boolean Arithmetic

Building a Virtual Computer

CS429: Computer Organization and Architecture

CS 261 Fall Mike Lam, Professor. Combinational Circuits

Overview of Compiler. A. Introduction

Systems I: Programming Abstractions

Interlude. Why Object Oriented Programming?

Appendix B: Test Scripting Language 1

CS 261 Fall Mike Lam, Professor. Logic Gates

CS1004: Intro to CS in Java, Spring 2005

Computer Systems. Binary Representation. Binary Representation. Logical Computation: Boolean Algebra

Bits and Bytes. How do computers compute?

Computer Organization and Levels of Abstraction

Supplementary Test 1

Run-time Environments

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation

Run-time Environments

17.1. Unit 17. Instruction Sets Picoblaze Processor

Objects and Graphics

This paper is not to be removed from the Examination Halls UNIVERSITY OF LONDON

4. Computer Architecture 1

Computer Organization and Levels of Abstraction

Assembler. Building a Modern Computer From First Principles.

CS4215 Programming Language Implementation

CSC 220: Computer Organization Unit 12 CPU programming

Lecture 8: Combinational Verilog. CSE 370, Autumn 2007 Benjamin Ylvisaker. Where We Are. Last lecture: Minimization with K!maps

Transcription:

Introduction: From Nand to Tetris Building a Modern Computer From First Principles www.nand2tetris.org Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 1

The course at a glance Objectives: Understand how hardware and software systems are built, and how they work together Learn how to break complex problems into simpler ones Learn how large scale development projects are planned and executed Have fun Methodology: Build a complete, general-purpose, and working computer system Play and experiment with this computer, at any level of interest. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 2

Some nand2tetris details 12 projects (We ll probably do 5 or 6) projects are done and simulated in HDL ( Description ) Software projects can be done in any language of your choice (we recommend Java) Projects methodology: o Design (API) + test materials are given o Implementation done by students Tools: simulators, tutorials, test scripts Book Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 3

Demo Pong, 1985 Pong, 2011 Pong, on our computer Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 4

Course theme and structure Human Thought Abstract design Chapters 9, 12 H.L. & Operating Sys. Compiler Chapters 10-11 Virtual Software VM Translator Chapters 7-8 Assembly Assembler Chapter 6 Computer Architecture Chapters 4-5 Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics (Abstraction implementation paradigm) Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 5

Application level: Pong (example app) Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 6

The big picture Human Thought Abstract design Chapters 9, 12 H.L. & Operating Sys. Compiler Chapters 10-11 Virtual Software VM Translator Chapters 7-8 Assembly Assembler Chapter 6 Computer Architecture Chapters 4-5 Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 7

High-level programming (our very own Jack language) /** A Graphic Bat for a Pong Game */ class Bat { field int x, y; // screen location of the bat's top-left corner field int width, height; // bat's width & height // The class constructor and most of the class methods are omitted /** Draws (color=true) or erases (color=false) the bat */ method void draw(boolean color) { do Screen.setColor(color); do Screen.drawRectangle(x,y,x+width,y+height); return; } Typical call to an OS method } /** Moves the bat one step (4 pixels) to the right. */ method void mover() { do draw(false); // erase the bat at the current location let x = x + 4; // change the bat's X-location // but don't go beyond the screen's right border if ((x + width) > 511) { let x = 511 - width; } do draw(true); // re-draw the bat in the new location return; } Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 8

Operating system level (our very own Jack OS) /** An OS-level screen driver that abstracts the computer's physical screen */ class Screen { static boolean currentcolor; // the current color // The Screen class is a collection of methods, each implementing one // abstract screen-oriented operation. Most of this code is omitted. } /** Draws a rectangle in the current color. */ // the rectangle's top left corner is anchored at screen location (x0,y0) // and its width and length are x1 and y1, respectively. function void drawrectangle(int x0, int y0, int x1, int y1) { var int x, y; let x = x0; while (x < x1) { let y = y0; while(y < y1) { do Screen.drawPixel(x,y); let y = y+1; } let x = x+1; } } Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 9

The big picture Human Thought Abstract design Chapters 9, 12 H.L. & Operating Sys. Compiler Chapters 10-11 Virtual Software VM Translator Chapters 7-8 Assembly Assembler Chapter 6 Computer Architecture Chapters 4-5 Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 10

A modern compilation model Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 11

Compilation 101 > Intermediate code Source code push x (x + width) > 511 parsing + 511 Code generation push width add push 511 gt x width Abstraction Syntax Analysis Parse Tree Semantic Synthesis Implementation Observations: Modularity Abstraction / implementation interplay The implementation uses abstract services from the level below. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 12

The Virtual (our very own VM, modeled after Java s JVM) if ((x+width)>511) { let x=511-width; } // VM implementation push x // s1 width x memory (before)......... 450 75 sp s2 75 450 push width add // s2 // s3 s4 s5 s9 push 511 gt if-goto L1 goto L2 // s4 // s5 // s6 // s7 sp 525 511 sp 1 sp 511 450 L1: push 511 push width sub pop x L2:... // s8 // s9 // s10 // s11 sp s10 61 width x memory (after)......... 450 61 Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 13

The big picture Human Thought Abstract design Chapters 9, 12 H.L. & Operating Sys. Compiler Chapters 10-11 Virtual Software VM Translator Chapters 7-8 Assembly Assembler Chapter 6 Computer Architecture Chapters 4-5 Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 14

Low-level programming (on the Hack computer) For now, ignore all details! Virtual machine program... push x push width add push 511 gt if-goto L1 goto L2 L1: push 511 push width sub pop x L2:... Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 15

Low-level programming (on the Hack computer) For now, ignore all details! Virtual machine program... push x push width add push 511 gt if-goto L1 goto L2 L1: push 511 push width sub pop x L2:... VM translator Assembly program // push 511 @511 D=A // D=511 @SP A=M M=D // *SP=D @SP M=M+1 // SP++ Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 16

Low-level programming (on the Hack computer) Virtual machine program For now, ignore all details!... push x push width add push 511 gt if-goto L1 goto L2 L1: push 511 push width sub pop x L2: VM translator Assembly program // push 511 @511 D=A // D=511 @SP A=M M=D // *SP=D @SP @SP M=M+1 // SP++ Assembler Executable 0000000000000000 1110110010001000... Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 17

The big picture Human Thought Abstract design Chapters 9, 12 H.L. & Operating Sys. Compiler Chapters 10-11 Virtual Software VM Translator Chapters 7-8 Assembly Assembler Chapter 6 Computer Architecture Chapters 4-5 Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 18

language semantics (our very own Hack platform) For now, ignore all details! Code semantics, as interpreted by the Hack hardware platform Instruction code (0= address inst.) Address Code syntax 0000000000000000 1111110111001000 @0 M=M-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0 0 Instruction code (1= compute inst.) ALU operation code Destination Code Jump Code (M-1) (M) (no jump) We need a hardware architecture that realizes this semantics The hardware platform should be designed to: o Parse instructions, and o Execute them. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 19

Computer architecture (Hack platform, approx.) For now, ignore all details! instruction Instruction Memory D A M ALU data out Data Memory (M) Program Counter address of next instruction data in RAM(A) A typical Von Neumann machine Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 20

The big picture Human Thought Abstract design Chapters 9, 12 H.L. & Operating Sys. Compiler Chapters 10-11 Virtual Software VM Translator Chapters 7-8 Assembly Assembler Chapter 6 Computer Architecture Chapters 4-5 Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 21

Logic design Combinational logic (leading to an ALU) Sequential logic (leading to a RAM) Putting the whole thing together (leading to a Computer) Using gate logic. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 22

Gate logic platform = inter-connected set of chips Chips are made of simpler chips, all the way down to elemantary logic gates Logic gate = hardware element that implements a certain Boolean function Every chip and gate has an interface, specifying WHAT it is doing, and an implementation, specifying HOW it is doing it. Interface Implementation a b Xor out a Not And a b out Or out 0 0 0 0 1 1 1 0 1 1 1 0 b Not And Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 23

Description (HDL) a Not And Or out b Not And CHIP Xor { IN a,b; OUT out; PARTS: Not(in=a,out=Nota); Not(in=b,out=Notb); And(a=a,b=Notb,out=w1); And(a=Nota,b=b,out=w2); Or(a=w1,b=w2,out=out); } Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 24

The tour ends: Interface One implementation option (CMOS) a b Nand out a b out 0 0 1 0 1 1 1 0 1 1 1 0 Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 25

The tour map, revisited Human Thought Abstract design Chapters 9, 12 Computer Architecture Chapters 4-5 H.L. & Operating Sys. Platform Compiler Chapters 10-11 Assembler Chapter 6 Gate Logic Chapters 1-3 Virtual Software VM Translator Chapters 7-8 Course overview: Building this world, from the ground up Chips & Logic Gates Electrical Engineering Assembly Physics Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Introduction slide 26