You are on page 1of 24

Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005

www.idc.ac.il/tecs

Introduction: Hello, World Below


Usage and Copyright Notice:
Copyright 2005 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.
The book web site, www.idc.ac.il/tecs , features 13 such 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, we will appreciate it if you will include in them a reference to the books
web site.
If you have any questions or comments, you can reach us at tecs.ta@gmail.com

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs , Course 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.idc.ac.il/tecs , Course Introduction

slide 2

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 programming language of your
choice (we recommend Java)
 Projects methodology:
 Design (API) + test materials are given
 Implementation done by students
 Tools: simulators, tutorials, test scripts
 Book
 Q&A policy
 Exam.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs , Course Introduction

slide 3

Demo

Pong, 1985

Pong, 2011

Pong, on our
computer

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs , Course Introduction

slide 4

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

(Abstractionimplementation paradigm)
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs , Course Introduction

slide 5

Application level: (say,) Pong

Ball
abstraction
Bat
abstraction

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs , Course Introduction

slide 6

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.idc.ac.il/tecs , Course Introduction

Electrical
Engineering
Physics

slide 7

High-level programming (Jack language)


/**
/** AA Graphic
Graphic Bat
Bat for
for aa Pong
Pong Game
Game */
*/
class
Bat
{
class Bat {
field
//
field int
int x,
x, y;
y;
// screen
screen location
location of
of the
the bat's
bat's top-left
top-left corner
corner
field
int
width,
height;
//
bat's
width
&
height
field int width, height;
// bat's width & height
//
// The
The class
class constructor
constructor and
and most
most of
of the
the class
class methods
methods are
are omitted
omitted
/**
/** Draws
Draws (color=true)
(color=true) or
or erases
erases (color=false)
(color=false) the
the bat
bat */
*/
method
void
draw(boolean
color)
{
method void draw(boolean color) {
do
do Screen.setColor(color);
Screen.setColor(color);
do
Screen.drawRectangle(x,y,x+width,y+height);
do Screen.drawRectangle(x,y,x+width,y+height);
return;
return;
}}

Typical call to
an OS method

/**
/** Moves
Moves the
the bat
bat one
one step
step (4
(4 pixels)
pixels) to
to the
the right.
right. */
*/
method
void
moveR()
{
method void moveR() {
do
do draw(false);
draw(false); //
// erase
erase the
the bat
bat at
at the
the current
current location
location
let
x
=
x
+
4;
//
change
the
bat's
X-location
let x = x + 4;
// change the bat's X-location
//
but
don't
go
beyond
// but don't go beyond the
the screen's
screen's right
right border
border
if
((x
+
width)
>
511)
{
if ((x + width) > 511) {
let
let xx == 511
511 -- width;
width;
}}
do
do draw(true);
draw(true); //
// re-draw
re-draw the
the bat
bat in
in the
the new
new location
location
return;
return;
}}

Ball
abstraction
Bat
abstraction

}}
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs , Course Introduction

slide 8

Operating system level (Jack OS)


/**
/** An
An OS-level
OS-level screen
screen driver
driver that
that abstracts
abstracts the
the computer's
computer's physical
physical screen
screen */
*/
class
class Screen
Screen {{
static
static boolean
boolean currentColor;
currentColor; //
// the
the current
current color
color
//
// The
The Screen
Screen class
class is
is aa collection
collection of
of methods,
methods, each
each implementing
implementing one
one
//
abstract
screen-oriented
operation.
Most
of
this
code
is
omitted.
// abstract screen-oriented operation. Most of this code is omitted.
/**
/** Draws
Draws aa rectangle
rectangle in
in the
the current
current color.
color. */
*/
//
the
rectangle's
top
left
corner
is
anchored
// the rectangle's top left corner is anchored at
at screen
screen location
location (x0,y0)
(x0,y0)
//
// and
and its
its width
width and
and length
length are
are x1
x1 and
and y1,
y1, respectively.
respectively.
function
function void
void drawRectangle(int
drawRectangle(int x0,
x0, int
int y0,
y0, int
int x1,
x1, int
int y1)
y1) {{
var
var int
int x,
x, y;
y;
let
x
=
x0;
let x = x0;
while
while (x
(x << x1)
x1) {{
let
let yy == y0;
y0;
while(y
while(y << y1)
y1) {{
do
do Screen.drawPixel(x,y);
Screen.drawPixel(x,y);
let
let yy == y+1;
y+1;
}}
let
let xx == x+1;
x+1;

Ball
abstraction
Bat
abstraction

}}
}}
}}

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs , Course Introduction

slide 9

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.idc.ac.il/tecs , Course Introduction

Electrical
Engineering
Physics

slide 10

A modern compilation model


Some
language

...

Some
compiler

...

Some Other
language

Jack
language

Proj. 9: building an app.


Proj. 12: building the OS

Jack
compiler

Some Other
compiler

Projects
10-11

VM language

VM
implementation
over CISC
platforms

CISC
machine
language

VM imp.
over RISC
platforms

RISC
machine
language

CISC
machine

RISC
machine

written in
a high-level
language

...
...

VM imp.
over the Hack
platform

VM
emulator

Projects
7-8

Hack
machine
language
Projects

...

other digital platforms, each equipped


with its VM implementation

1-6
Any
computer

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs , Course Introduction

Hack
computer
slide 11

Compilation 101
Intermediate code

>
Source code
(x
(x ++ width)
width) >> 511
511

parsing

511

Code
generation

push
push xx
push
push width
width
add
add
push
push 511
511
gt
gt

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.idc.ac.il/tecs , Course Introduction

slide 12

The Virtual Machine (our stack-based VM, quite similar to Javas JVM)
if ((x+width)>511) {
let x=511-width;
}

...
width

75

450

...
// VM implementation

s2

memory (before)

450
sp

75

...

push x

// s1

push width

// s2

add

// s3

push 511

// s4

525

gt

// s5

511

if-goto L1

// s6

goto L2

// s7

s4

s5

s9

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.idc.ac.il/tecs , Course Introduction

450

61

...
slide 13

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.idc.ac.il/tecs , Course Introduction

Electrical
Engineering
Physics

slide 14

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

L1:

D=A

// 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.idc.ac.il/tecs , Course Introduction

slide 15

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.idc.ac.il/tecs , Course Introduction

Electrical
Engineering
Physics

slide 16

For now,
ignore all
details!

Machine language semantics (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

1 1

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:
 Parse instructions, and
 Execute them.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs , Course Introduction

slide 17

For now,
ignore all
details!

Computer architecture (Hack platform, approx.)


instruction

Instruction
Memory

ALU

Data
Memory
data out

(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.idc.ac.il/tecs , Course 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.idc.ac.il/tecs , Course Introduction

Electrical
Engineering
Physics

slide 19

Logic design
 Combinational logic
 Sequential logic

(leading to an ALU)

(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.idc.ac.il/tecs , Course Introduction

slide 20

Gate logic
 Hardware platform = inter-connected set of chips
 Chips are made of simpler chips, all the way down to 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
Xor

out

And
Not

Or

out

0
0
1
1

0
1
0
1

0
1
1
0

out

Not

And

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs , Course Introduction

slide 21

Hardware Description Language (HDL)


a
And
Not
Or

out

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.idc.ac.il/tecs , Course Introduction

slide 22

The tour ends:


One implementation option (CMOS)

Interface

a
out

Nand

b
a

out

0
0
1
1

0
1
0
1

1
1
1
0

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs , Course Introduction

slide 23

The tour map, revisted

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.idc.ac.il/tecs , Course Introduction

Electrical
Engineering
Physics

slide 24

You might also like