lecture 00 introduction

advertisement
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
Usage and Copyright Notice:
Copyright © Noam Nisan and Shimon Schocken
This presentation contains lecture materials that accompany the textbook “The Elements of
Computing Systems” by Noam Nisan & Shimon Schocken, MIT Press, 2005.
We provide both PPT and PDF versions.
Our web site, www.nand2tetris.org ,features a set of presentations, one for each book chapter.
Each presentation is designed to support about 3 hours of classroom or self-study instruction.
You are welcome to use or edit this presentation as you see fit for instructional and noncommercial purposes.
If you use our materials, please include a reference to www.nand2tetris.org
If you have any questions or comments, please write us at nand2tetris@gmail.com
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 2
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 3
Some course details
 12 projects, can be done by pairs
 Hardware projects are done and simulated in HDL
(Hardware Description Language)
 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
 Q&A policy
 Course grade.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 4
Demo
Pong, 1985
Pong, 2011
Pong, on our
computer
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 5
Course theme and structure
Human
Thought
Abstract design
Software
hierarchy
abstract interface
Chapters 9, 12
H.L. Language
&
Operating Sys.
Compiler
abstract interface
Chapters 10 - 11
Virtual
Machine
VM Translator
abstract interface
Chapters 7 - 8
Assembly
Language
Assembler
Chapter 6
abstract interface
Machine
Language
Computer
Architecture
abstract interface
Chapters 4 - 5
Hardware
Platform
Hardware
hierarchy
Gate Logic
abstract interface
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 6
Application level: Pong (example app)
Ball
abstraction
Bat
abstraction
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 7
The big picture
Human
Thought
Abstract design
Software
hierarchy
abstract interface
Chapters 9, 12
H.L. Language
&
Operating Sys.
Compiler
abstract interface
Chapters 10 - 11
Virtual
Machine
VM Translator
abstract interface
Chapters 7 - 8
Assembly
Language
Assembler
Chapter 6
abstract interface
Machine
Language
Computer
Architecture
abstract interface
Chapters 4 - 5
Hardware
Platform
Hardware
hierarchy
Gate Logic
abstract interface
Chapters 1 - 3
Chips &
Logic Gates
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
Electrical
Engineering
Physics
slide 8
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;
}
Ball
abstraction
Bat
abstraction
}
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 9
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;
Ball
abstraction
Bat
abstraction
}
}
}
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 10
The big picture
Human
Thought
Abstract design
Software
hierarchy
abstract interface
Chapters 9, 12
H.L. Language
&
Operating Sys.
Compiler
abstract interface
Chapters 10 - 11
Virtual
Machine
VM Translator
abstract interface
Chapters 7 - 8
Assembly
Language
Assembler
Chapter 6
abstract interface
Machine
Language
Computer
Architecture
abstract interface
Chapters 4 - 5
Hardware
Platform
Hardware
hierarchy
Gate Logic
abstract interface
Chapters 1 - 3
Chips &
Logic Gates
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
Electrical
Engineering
Physics
slide 11
A modern compilation model
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 12
Compilation 101
Intermediate code
>
Source code
(x + width) > 511
push x
parsing
+
511
Code
generation
push width
add
push 511
gt
x
Abstraction
Syntax
Analysis
width
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 13
The Virtual Machine (our very own VM, modeled after Java’s JVM)
if ((x+width)>511) {
let x=511-width;
}
...
width
75
450
...
// VM implementation
s2
memory (before)
x
450
sp
75
...
push x
// s1
push width
// s2
add
// s3
s4
push 511
// s4
525
gt
// s5
511
if-goto L1
// s6
goto L2
// s7
s5
s9
1
511
sp
450
sp
sp
L1:
push 511
// s8
push width
// s9
sub
// s10
pop x
// s11
s10
memory (after)
...
61
sp
width
...
L2:
...
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
450
x
61
...
slide 14
The big picture
Human
Thought
Abstract design
Software
hierarchy
abstract interface
Chapters 9, 12
H.L. Language
&
Operating Sys.
Compiler
abstract interface
Chapters 10 - 11
Virtual
Machine
VM Translator
abstract interface
Chapters 7 - 8
Assembly
Language
Assembler
Chapter 6
abstract interface
Machine
Language
Computer
Architecture
abstract interface
Chapters 4 - 5
Hardware
Platform
Hardware
hierarchy
Gate Logic
abstract interface
Chapters 1 - 3
Chips &
Logic Gates
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
Electrical
Engineering
Physics
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:
...
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 16
Low-level programming (on the Hack computer)
For now,
ignore all
details!
Virtual machine program
...
push x
push width
add
push 511
VM translator
Assembly program
gt
if-goto L1
// push 511
goto L2
@511
D=A
L1:
push 511
@SP
push width
A=M
sub
M=D
pop x
@SP
L2:
// D=511
// *SP=D
M=M+1 // SP++
...
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 17
Low-level programming (on the Hack computer)
For now,
ignore all
details!
Virtual machine program
...
push x
push width
add
push 511
gt
VM
translator
Assembly program
if-goto L1
// push 511
goto L2
@511
D=A
L1:
// D=511
push 511
@SP
push width
A=M
sub
M=D
pop x
@SP
@SP
M=M+1 // SP++
L2:
Assembler
// *SP=D
Executable
0000000000000000
1110110010001000
...
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 18
The big picture
Human
Thought
Abstract design
Software
hierarchy
abstract interface
Chapters 9, 12
H.L. Language
&
Operating Sys.
Compiler
abstract interface
Chapters 10 - 11
Virtual
Machine
VM Translator
abstract interface
Chapters 7 - 8
Assembly
Language
Assembler
Chapter 6
abstract interface
Machine
Language
Computer
Architecture
abstract interface
Chapters 4 - 5
Hardware
Platform
Hardware
hierarchy
Gate Logic
abstract interface
Chapters 1 - 3
Chips &
Logic Gates
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
Electrical
Engineering
Physics
slide 19
For now,
ignore all
details!
Machine language semantics (our very own Hack platform)
Code semantics, as interpreted by the Hack hardware platform
Instruction code
(0=“address” inst.)
Address
Code syntax
0
0000000000000000
@0
1111110111001000
M=M-1
1
0
1
0
0
1 1
Instruction code
(1=“compute” inst.)
0
1
0
1
0
0
0
1
0
1
0
1
0
0
0
0
0
1
0
0
0
0
0
0
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 20
For now,
ignore all
details!
Computer architecture (Hack platform, approx.)
instruction
D
A
ALU
Instruction
Memory
Data
Memory
data out
(M)
M
address of next
instruction
Program
Counter
data in
RAM(A)
 A typical Von Neumann machine
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 21
The big picture
Human
Thought
Abstract design
Software
hierarchy
abstract interface
Chapters 9, 12
H.L. Language
&
Operating Sys.
Compiler
abstract interface
Chapters 10 - 11
Virtual
Machine
VM Translator
abstract interface
Chapters 7 - 8
Assembly
Language
Assembler
Chapter 6
abstract interface
Machine
Language
Computer
Architecture
abstract interface
Chapters 4 - 5
Hardware
Platform
Hardware
hierarchy
Gate Logic
abstract interface
Chapters 1 - 3
Chips &
Logic Gates
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
Electrical
Engineering
Physics
slide 22
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 23
Gate logic
 Hardware 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.
Implementation
Interface
a
a
Xor
out
And
Not
b
Or
a
b
out
0
0
1
1
0
1
0
1
0
1
1
0
out
Not
b
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
And
slide 24
Hardware Description Language (HDL)
a
And
Not
Or
out
Not
b
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 25
The tour ends:
One implementation option (CMOS)
Interface
a
out
Nand
b
a
b
out
0
0
1
1
0
1
0
1
1
1
1
0
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
slide 26
The tour map, revisited
Human
Thought
Abstract design
Software
hierarchy
abstract interface
Chapters 9, 12
H.L. Language
&
Operating Sys.
Compiler
abstract interface
Chapters 10 - 11
Virtual
Machine
VM Translator
abstract interface
Chapters 7 - 8
Assembly
Language
Assembler
Chapter 6
Course overview:
Building this world,
from the ground up
abstract interface
Machine
Language
Computer
Architecture
abstract interface
Chapters 4 - 5
Hardware
Platform
Hardware
hierarchy
Gate Logic
abstract interface
Chapters 1 - 3
Chips &
Logic Gates
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Introduction
Electrical
Engineering
Physics
slide 27
Download