CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005 CS101 1 Course at a Glance Here’s a constant and an operator. Now go build a computer How? One step at a time False Nand CS101: Digital Systems Construction Building a Modern Computer From First Principles Instructor: Shimon Schocken CS101 2 Course at a Glance The Course Theme: Let’s Build a Computer Course Goals Explicit: Let’s build a computer! Implicit: Understand ... Key hardware & software abstractions Key interfaces: compilation, VM, O/S Appreciate: Science history and method Plus: Have fun. CS101 Course Methodology Constructive: hands-on Self-contained: only requirement is programming Guided: all "plans" are given Focused: Occam’s razor. False Nand
20
Embed
CS101: Digital Systems Construction intro.pdf · CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005 CS101 15 Course at a Glance Hardware projects various
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101 1 Course at a Glance
Here’s a constantand an operator.Now go build a computer
How?
One step at a time
False
Nand
CS101: Digital Systems Construction
Building a Modern Computer From First PrinciplesInstructor: Shimon Schocken
CS101 2 Course at a Glance
The Course Theme: Let’s Build a ComputerCourse Goals
Explicit: Let’s build a computer!
Implicit: Understand ...
Key hardware & software abstractions
Key interfaces: compilation, VM, O/S
Appreciate: Science history and method
Plus: Have fun.CS101
Course Methodology
Constructive: hands-on
Self-contained: only requirement is programming
Guided: all "plans" are given
Focused: Occam’s razor.False
Nand
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101 3 Course at a Glance
Sample Applications
CS101 4 Course at a Glance
Sample Applications
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101 5 Course at a Glance
assembler
machine language
assembly
stack machine
virtual machine
compiler
operating system prog. language
Software hierarchy
various combinational chips various sequential chips
ALU / CPU memory units
computer architecture
machine language
essential theory(Boolean algebra and gate logic)
hardware platform
Course map
P1
P2 P3
P5
P4
P = Instructional unit(chapter/lecture/project/week)
Each unit is self-contained
Each unit provides the building blocks with which we build the unit above it.
P7,8
P9
P10,11
P12
P6
CS101 6 Course at a Glance
Hardware projects
Tools:
HDL (Hard. Descr. Language)
Test Description Language
Hardware simulator.
Hardware projects:
P1: Elementary logic gates
P2: Combinational gates (ALU)
P3: Sequential gates (memory)
P4: Machine language
P5: Computer architecturevarious combinational chips various sequential chips
ALU / CPU memory units
computer architecture
machine language
essential theory(Boolean algebra and gate logic)
hardware platform
P1
P2 P3
P5
P4
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101 7 Course at a Glance
Project 1: Elementary logic gates
Given: Nand(a,b), false
Not(a) = Nand(a,a)
true = Not(false)
And(a,b) = Not(Nand(a,b))
Or(a,b) = . . .
Mux(s,a,b) = . . .
Etc. - 12 gates altogether.
a b Nand(a,b)0 0 10 1 1 1 0 1 1 1 0
a b Nand(a,b)0 0 10 1 1 1 0 1 1 1 0
CS101 8 Course at a Glance
outa
bAnd
a b out0 0 00 1 0 1 0 0 1 1 1
a b out0 0 00 1 0 1 0 0 1 1 1
And.cmp
load And.hdl,output-file And.out,compare-to And.cmp,output-list a b out;set a 0,set b 0,eval,output;set a 0,set b 1,eval,output;set a 1,set b 0,eval,output;set a 1, set b 1, eval, output;
load And.hdl,output-file And.out,compare-to And.cmp,output-list a b out;set a 0,set b 0,eval,output;set a 0,set b 1,eval,output;set a 1,set b 0,eval,output;set a 1, set b 1, eval, output;
And.tstAnd.hdl
CHIP And { IN a, b;
OUT out;
// implementation missing}
CHIP And { IN a, b;
OUT out;
// implementation missing}
Building an And gate
Contract:
When running your .hdl on our .tst, your .out should be the same asour .cmp.
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101 9 Course at a Glance
CHIP And { IN a, b;
OUT out;Nand(a = a,
b = b,out = x);
Not(in = x, out = out)}
CHIP And { IN a, b;
OUT out;Nand(a = a,
b = b,out = x);
Not(in = x, out = out)}
Implementation: And(a,b) = Not(Nand(a,b))
outNOT
a
b
outNANDa in out
xb
Building an And gate
And.hdl
CS101 10 Course at a Glance
Hardware simulator
And
And
Or out
a
b
test script
gate diagram
HDL program
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101 11 Course at a Glance
CHIP Add16 {
IN a[16], b[16];
OUT out[16];
PARTS:
...
FullAdder(...);
...
}
CHIP Add16 {
IN a[16], b[16];
OUT out[16];
PARTS:
...
FullAdder(...);
...
}
CHIP FullAdder {
IN a, b, c;
OUT sum,
carry;
PARTS:
HalfAdder(...);
...
}
CHIP FullAdder {
IN a, b, c;
OUT sum,
carry;
PARTS:
HalfAdder(...);
...
}
CHIP HalfAdder {
IN a, b;
OUT sum,
carry;
PARTS:
Xor(...);
...
}
CHIP HalfAdder {
IN a, b;
OUT sum,
carry;
PARTS:
Xor(...);
...
}
CHIP Xor {
IN a, b;
OUT out;
PARTS:
...
And(...);
}
CHIP Xor {
IN a, b;
OUT out;
PARTS:
...
And(...);
}
CHIP And {
IN a, b;
OUT out;
PARTS:
Not(...);
...
}
CHIP And {
IN a, b;
OUT out;
PARTS:
Not(...);
...
}
CHIP Not {
IN in;
OUT out;
PARTS:
Nand(a=in,b=in,out=out);
}
CHIP Not {
IN in;
OUT out;
PARTS:
Nand(a=in,b=in,out=out);
}
CHIP Nand {
IN a, b;
OUT out;
PARTS:
BUILTIN Nand; // Implemented by Nand.java
}
CHIP Nand {
IN a, b;
OUT out;
PARTS:
BUILTIN Nand; // Implemented by Nand.java
}
Chip anatomy
CS101 12 Course at a Glance
Project 2: Combinational chips
h alf ad d er
a s um
b c arryfu l l
ad d er
asum
bc arry
c
outa
16
1 6 -b itad d e r
b16
16
zx no
zr
nx zy ny f
ALU
ng
16 bits
16 bits
x
y 16 bitsout
out(x, y, control bits) =
x+y, x-y, y–x,
0, 1, -1,
x, y, -x, -y,
x!, y!,
x+1, y+1, x-1, y-1,
x&y, x|y
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101 29 Course at a Glance
VM code
virtual memory segments
working stack (the RAM is
not part of the VM)
default test script
host RAMglobal stack
CS101 30 Course at a Glance
Projects 7,8: Implement the VM over the Hack platform
Mult.vm
function mult 2 // 2 local variablespush constant 0 // result=0pop local 0push argument 1 // j=ypop local 1
label looppush constant 0 // if j==0 goto endpush local 1eqif-goto endpush local 0 // result=result+xpush argument 0addpop local 0push local 1 // j=j-1push constant 1subpop local 1goto loop
label endpush local 0 // return resultreturn
function mult 2 // 2 local variablespush constant 0 // result=0pop local 0push argument 1 // j=ypop local 1
label looppush constant 0 // if j==0 goto endpush local 1eqif-goto endpush local 0 // result=result+xpush argument 0addpop local 0push local 1 // j=j-1push constant 1subpop local 1goto loop
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101 31 Course at a Glance
assembler
machine language
assembly
stack machine
virtual machine
compiler
operating system prog. language
Software hierarchy
Software projects
CS101 32 Course at a Glance
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; }
/** 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; }}
Ballabstraction
Batabstraction
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101 35 Course at a Glance
assembler
machine language
assembly
stack machine
virtual machine
compiler
operating system prog. language
Software hierarchy
Software projects
CS101 36 Course at a Glance
/** Computes the average of a sequence of integers. */class Main {function void main() {var Array a; var int length;var int i, sum;
let length = Keyboard.readInt(”How many numbers? ”);let a = Array.new(length); // Constructs the arraylet i = 0;
while (i < length) {let a[i] = Keyboard.readInt(”Enter the next number: ”);let sum = sum + a[i];let i = i + 1;
}
do Output.printString(”The average is: ”);do Output.printInt(sum / length);do Output.println();return;
}}
/** Computes the average of a sequence of integers. */class Main {function void main() {var Array a; var int length;var int i, sum;
let length = Keyboard.readInt(”How many numbers? ”);let a = Array.new(length); // Constructs the arraylet i = 0;
while (i < length) {let a[i] = Keyboard.readInt(”Enter the next number: ”);let sum = sum + a[i];let i = i + 1;
}
do Output.printString(”The average is: ”);do Output.printInt(sum / length);do Output.println();return;
}}
Typical Jack code
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101 37 Course at a Glance
OS Libraries
Math: Provides basic mathematical operations;
String: Implements the String type and string-related operations;
Array: Implements the Array type and array-related operations;
Output: Handles text output to the screen;
Screen: Handles graphic output to the screen;
Keyboard: Handles user input from the keyboard;
Memory: Handles memory operations;
Sys: Provides some execution-related services.
CS101 38 Course at a Glance
Recap
250 lines of Jack code1000 lines of VM code
4,000 lines of Assembly30,000 lines of Hack code
500,000 bits2,000,000 logic gates
1 Godlogicchip-set
architecturemachine language
assemblyvirtual machine
high-level language / OS
application (e.g. Pong) 15 obj-oriented bat / ball operations
SW
False
Nand
ALU
Mux
D
Mux
reset
inM
addressM
pc
outM
A/Minstruction
decode
C
C
C
C
C
D
A
PC
C
C
A
A
A
M
ALU output
reset
reset
writeMC
C
HW
CS101, Digital Systems Construction, Shimon Schocken Harvard University, Fall 2005
CS101 39 Course at a Glance
“We deliberate not about ends, but about means. For a doctor does not deliberate whether he shall heal, nor an orator whether he shall persuade ... They assume the end and consider how and by what means it is attained, and if it seems easily and best produced thereby; And if it is achieved by some means, they consider how it will be achieved, and by what means this will be achieved, until they come to the first cause. And what is last in the order of analysis seems to be first in the order of becoming.”