Академический Документы
Профессиональный Документы
Культура Документы
Nand to Tetris
Building a Modern Computer from First Principles
Chapter 1
Boolean Logic
These slides support chapter 1 of the book
The Elements of Computing Systems
By Noam Nisan and Shimon Schocken
MIT Press
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 1
Chapter 1: Boolean logic
• Boolean logic
• Hardware simulation
• Multi-bit buses
• Project 1 overview
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 2
Boolean Values
F T
N Y
0 1
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 3
Boolean Operations
x And y x Or y Not(x)
𝑥 ∧ 𝑥 𝑥∨𝑦 ¬ 𝑥
x y And x y Or x Not
0 0 0 0 0 0 0 1
0 1 0 0 1 1 1 0
1 0 0 1 0 1
1 1 1 And 1 1 1
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 4
Boolean Expressions
Not(0 Or 1) =
Not(1) =
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 5
Boolean Functions
x y z f
0 0 0
0 0 1 1
(0 And 0) Or (Not(0) And 1) =
0 1 0
0 Or (1 And 1) =
0 1 1
0 Or 1 = 1
1 0 0
1 0 1
1 1 0 f
1 1 1
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 6
Boolean Functions
x y z f
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1 truth table
1 0 0 0
1 0 1 0
1 1 0 1 f
1 1 1 1
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 7
Boolean Identities
• (x And y) = (y And x)
commutative
• (x Or y) = (y Or x) laws
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 8
Boolean Algebra
De Morgan law
Not(Not(x) And Not(x Or y)) =
associative law
Not(Not(x) And (Not(x) And Not(y))) =
Not(Not(x)) Or Not(Not(y)) =
double negation
x Or y
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 9
Boolean Algebra
x y Or
0 0 0
0 1 1
1 0 1
1 1 1
x Or y
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 10
Chapter 1: Boolean logic
• Boolean logic
• Hardware simulation
• Multi-bit buses
• Project 1 overview
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 11
Boolean expression è truth table
f(x, y, z) = (x And y) Or (Not(x) And z)
x y z f
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 12
Boolean expression ç truth table
f(x, y, z) = (x And y) Or (Not(x) And z)
x y z f
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 13
From truth table to a Boolean expression
x y z f
0 0 0 1 1
(Not(x) And Not(y) And Not(z))
0 0 1 0 0
0 1 0 1 0
0 1 1 0 0
1 0 0 1 0
1 0 1 0 0
1 1 0 0 0
1 1 1 0 0
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 14
From truth table to a Boolean expression
x y z f
0 0 0 1 0
0 0 1 0 0
0 1 0 1 1
0 1 1 0 0 (Not(x) And y And Not(z))
1 0 0 1 0
1 0 1 0 0
1 1 0 0 0
1 1 1 0 0
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 15
From truth table to a Boolean expression
x y z f
0 0 0 1 0
0 0 1 0 0
0 1 0 1 1
0 1 1 0 0
1 0 0 1 1
1 0 1 0 0 (x And Not(y) And Not(z))
1 1 0 0 0
1 1 1 0 0
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 16
From truth table to a Boolean expression
x y z f
0 0 0 1 1
(Not(x) And Not(y) And Not(z))
0 0 1 0
0 1 0 1 1
0 1 1 0 (Not(x) And y And Not(z))
1 0 0 1 1
1 0 1 0 (x And Not(y) And Not(z))
1 1 0 0
1 1 1 0
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 17
From truth table to a Boolean expression
x y z f
0 0 0 1
(Not(x) And Not(y) And Not(z)) Or
0 0 1 0
0 1 0 1
0 1 1 0 (Not(x) And y And Not(z)) Or
1 0 0 1
1 0 1 0 (x And Not(y) And Not(z))
1 1 0 0
(Not(x) And Not(y) And Not(z)) Or
1 1 1 0
(Not(x) And y And Not(z)) Or
(x And Not(y) And Not(z)) =
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 18
From truth table to a Boolean expression
x y z f
0 0 0 1
(Not(x) And Not(y) And Not(z)) Or
0 0 1 0
0 1 0 1
0 1 1 0 (Not(x) And y And Not(z)) Or
1 0 0 1
1 0 1 0 (x And Not(y) And Not(z))
1 1 0 0
(Not(x) And Not(y) And Not(z)) Or
1 1 1 0
(Not(x) And y And Not(z)) Or
(x And Not(y) And Not(z)) =
(Not(x) And Not(z)) Or (x And Not(y) And Not(z)) =
(Not(x) And Not(z)) Or (Not(y) And Not(z)) =
Not(z) And (Not(x) Or Not(y))
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 19
Theorem
Lemma: Any Boolean function can be represented using an expression containing
And, Or And Not operations.
Proof:
Use the truth table to Boolean expression method
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 20
Nand
x y Nand
0 0 1
0 1 1
1 0 1
1 1 0
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 21
Theorem (revisited)
Lemma: Any Boolean function can be represented using an expression containing
And, Or And Not operations.
Proof:
Use the truth table to Boolean expression method
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 22
Chapter 1: Boolean logic
• Boolean logic
• Hardware simulation
• Multi-bit buses
• Project 1 overview
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 23
Building a logic gate
a
Xor ou
t
?
b
The Process:
ü Design the gate architecture
ü Specify the architecture in HDL
ü Test the chip in a hardware simulator
• Optimize the design
• Realize the optimized design in silicon.
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 24
Design: from requirements to interface
a a b out
0 0 0
Requirement:
Xor ou
t 0 1 1 Build a gate that
b
1 0 1 delivers this
functionality
outputs 1 if one, and only 1 1 0
one, of its inputs, is 1.
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 25
Design: from requirements to gate diagram
a a b out
0 0 0
Requirement:
Xor ou
t 0 1 1 Build a gate that
b
1 0 1 delivers this
functionality
outputs 1 if one, and only 1 1 0
one, of its inputs, is 1.
a
And
General idea:
Not
out=1 when:
a And Not(b) Or out
Not
Or
b And Not(a) And
b
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 26
Design: from gate diagram to HDL
a
a out
b
And
in out aAndNotb
Not
notb
a
out
b
Or out
Not nota
in out
notaAndb
a
out
And
b
b
CHIP Xor {
IN a, b;
OUT out;
PARTS:
// implementation missing
}
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 27
Design: from gate diagram to HDL
a
a out
b
And
in out aAndNotb
Not
notb
a
out
b
Or out
Not nota
in out
notaAndb
a
out
And
b
b
CHIP Xor {
IN a, b;
OUT out;
PARTS:
Not (in=a, out=nota);
Not (in=b, out=notb);
And (a=a, b=notb, out=aAndNotb);
And (a=nota, b=b, out=notaAndb);
Or (a=aAndNotb, b=notaAndb, out=out);
}
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 29
Hardware description languages
Common HDLs:
• VHDL
• Verilog
• Many more HDLs…
Our HDL
• Similar in spirit to other HDLs
• Minimal and simple
• Provides all you need for this course
• HDL Documentation:
q Textbook / Appendix A
q www.nand2tetris.org / HDL Survival Guide
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 30
Chapter 1: Boolean logic
• Boolean logic
• Hardware simulation
• Multi-bit buses
• Project 1 overview
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 31
Hardware simulation in a nutshell
CHIP Xor {
IN a, b;
OUT out; HDL code
PARTS:
Not (in=a, out=nota);
Not (in=b, out=notb);
And (a=a, b=notb, out=aAndNotb); simulate
And (a=nota, b=b, out=notaAndb);
Or (a=aAndNotb, b=notaAndb, out=out);
} load Xor.hdl, test script hardware
output-file And.out,
output-list a b out;
set a 0, set b 0, eval, output;
simulator
set a 0, set b 1, eval, output;
set a 1, set b 0, eval, output;
set a 1, set b 1, eval, output;
Simulation options:
• Interactive
• Script-based
• With / without output and compare files
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 32
Interactive simulation (using Xor as an example)
Xor.hdl
CHIP Xor { a
IN a, b; And
OUT out; Not aAndNotb
notb
PARTS:
Or out
Not (in=a, out=nota);
Not nota
Not (in=b, out=notb);
notaAndb
And (a=a, b=notb, out=aAndNotb);
And (a=nota, b=b, out=notaAndb); And
b
Or (a=aAndNotb, b=notaAndb, out=out);
}
Simulation process:
• Load the HDL file into the hardware simulator
• Enter values (0’s and 1’s) into the chip’s input pins (e.g. a and b)
• Evaluate the chip’s logic
• Inspect the resulting values of:
q Output pins (e.g. out)
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 33
Interactive simulation
2. evaluate the
chip logic
3. inspect
output pins
1. manipulate
input pins
4. inspect
internal pins
HDL
code
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 34
Interactive simulation
HW Simulator
demo
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 35
Script-based simulation
Xor.hdl Xor.tst
CHIP Xor {
load Xor.hdl;
IN a, b; tested
OUT out; set a 0, set b 0, eval;
chip set a 0, set b 1, eval;
PARTS: set a 1, set b 0, eval;
Not (in=a, out=nota); set a 1, set b 1, eval;
Not (in=b, out=notb);
And (a=a, b=notb, out=aAndNotb);
And (a=nota, b=b, out=notaAndb);
Or (a=aAndNotb, b=notaAndb, out=out);
test script = series of
}
commands to the simulator
Benefits:
• “Automatic” testing
• Replicable testing
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 36
Script-based simulation, with an output file
Xor.hdl Xor.tst
CHIP Xor {
load Xor.hdl, test
IN a, b; tested
tested
OUT out; output-file Xor.out, script
chip
chip output-list a b out;
PARTS: set a 0, set b 0, eval, output;
Not (in=a, out=nota); set a 0, set b 1, eval, output;
Not (in=b, out=notb);
set a 1, set b 0, eval, output;
And (a=a, b=notb, out=aAndNotb);
set a 1, set b 1, eval, output;
And (a=nota, b=b, out=notaAndb);
Or (a=aAndNotb, b=notaAndb, out=out);
}
Xor.out
The logic of a typical test script | a | b |out|
| 0 | 0 | 0 | Output File, created
q Initialize: by the test script as a
| 0 | 1 | 1 |
q Load an HDL file | 1 | 0 | 1 | side-effect of the
q Create an empty output file | 1 | 1 | 0 | simulation process
q List the names of the pins whose
values will be written to the output file
q Repeat:
q set – eval - output
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 37
Script-based simulation
inspect the
run output file
the script
test
script
HDL
code
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 38
Script-based simulation
HW Simulator
demo
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 39
Hardware simulators
• There are many of them!
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 40
Revisiting script-based simulation with output files
Xor.hdl Xor.tst
Xor.out
| a | b |out|
| 0 | 0 | 0 |
Output file, created by the | 0 | 1 | 1 |
test script as a side-effect of | 1 | 0 | 1 |
the simulation process | 1 | 1 | 0 |
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 41
Script-based simulation, with compare files
Xor.hdl Xor.tst
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 42
Behavioral simulation
Xor.hdl Xor.tst
CHIP Xor {
load Xor.hdl,
IN a, b; built-in chip test
output-file Xor.out,
OUT out; implementation script
output-list a b out;
BUILTIN Xor set a 0, set b 0, eval, output;
// Built-in chip implementation, set a 0, set b 1, eval, output;
// can execute in the hardware set a 1, set b 0, eval, output;
// simulator like any other chip. set a 1, set b 1, eval, output;
}
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 43
Hardware construction projects
• The players (first approximation):
q System architects
q Developers
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 44
The developer’s view (of, say, a Xor gate)
Xor.hdl Xor.tst
/** returns 1 if (a != b) */ load Xor.hdl,
test
stub output-file Xor.out,
script
CHIP Xor {
file compare-to Xor.cmp
IN a, b;
output-list a b out;
OUT out;
set a 0, set b 0, eval, output;
set a 0, set b 1, eval, output;
PARTS:
// Implementation missing set a 1, set b 0, eval, output;
} set a 1, set b 1, eval, output;
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 45
Chapter 1: Boolean logic
• Boolean logic
• Hardware simulation
• Multi-bit buses
• Project 1 overview
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 46
Arrays of Bits
• Sometimes we wish to manipulate an array of bits as one group
47
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 47
Example: adding 16-bit integers
/* 16
* Adds two 16-bit values. a 16
*/ 16-bit
out
CHIP Add16 { 16 adder
IN a[16], b[16]; b
OUT out[16];
PARTS:
...
} /*
* Adds three 16-bit inputs.
*/
CHIP Add3Way16 {
IN first[16], second[16], third[16];
OUT out[16];
PARTS:
Add16(a=first, b=second, out=temp);
Add16(a=temp, b=third, out=out);
}
48
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 48
Working with individual bits within buses
/*
* 4-way And: Ands 4 bits.
*/
CHIP And4Way {
IN a[4];
OUT out;
PARTS:
And(a=a[0], b=a[1], out=t01);
And(a=t01, b=a[2], out=t012);
And(a=t012, b=a[3], out=out);
}
49
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 49
Working with individual bits within buses
/*
* Bit-wise And of two 4-bit inputs
*/
CHIP And4 {
IN a[4], b[4];
OUT out[4];
PARTS:
And(a=a[0], b=b[0], out=out[0]);
And(a=a[1], b=b[1], out=out[1]);
And(a=a[2], b=b[2], out=out[2]);
And(a=a[3], b=b[3], out=out[3]);
}
50
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 50
Sub-buses
Buses can be composed from (and decomposed into) sub-buses
...
IN lsb[8], msb[8], …
...
Add16(a[0..7]=lsb, a[8..15]=msb, b=…, out=…);
Add16(…, out[0..3]=t1, out[4..15]=t2);
51
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 51
Chapter 1: Boolean logic
• Boolean logic
• Hardware simulation
• Multi-bit buses
• Project 1 overview
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 52
Nand to Tetris course methodology
one step
at a time
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 53
Project 1
Given: Nand
Goal: Build the following gates:
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 54
Project 1
Given: Nand
Goal: Build the following gates:
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 55
Multiplexor
a b sel out sel out
0 0 0 0 0 a
0 1 0 0 1 b
1 0 0 1
1 1 0 1
abbreviated
0 0 1 0 truth table
if (sel==0) 0 1 1 1
out=a 1 0 1 0
else 1 1 1 1
out=b
CHIP AndMuxOr {
IN a, b, sel;
OUT out;
PARTS:
And (a=a, b=b, out=andOut);
Or (a=a, b=b, out=orOut);
Mux (a=andOut, b=orOut, sel=sel, out=out);
}
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 57
Multiplexor implementation
Mux.hdl
CHIP Mux {
Implementation tip:
IN a, b, sel;
OUT out; Can be implemented with
PARTS: And, Or, and Not gates
// Put your code here:
}
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 58
Demultiplexor
in sel a b
if (sel==0) 0 0 0 0
{a,b}={in,0} 0 1 0 0
else 1 0 1 0
{a,b}={0,in} 1 1 0 1
DMux.hdl
• Acts like the “inverse” of a multiplexor CHIP DMux {
IN in, sel;
• Distributes the single input value into OUT a, b;
one of two possible destinations
PARTS:
// Put your code here:
}
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 59
Example: Multiplexing / demultiplexing in communications networks
source destination
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 60
Project 1
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 61
And16
CHIP And16 {
IN a[16], b[16];
OUT out[16];
PARTS:
// Put your code here:
}
a = 1 0 1 0 1 0 1 1 0 1 0 1 1 1 0 0
b = 0 0 1 0 1 1 0 1 0 0 1 0 1 0 1 0
out = 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 63
16-bit, 4-way multiplexor
Mux4Way16.hdl
CHIP Mux4Way16 { Implementation tip:
IN a[16], b[16], c[16], d[16],
sel[2];
Can be built from several Mux16 gates
OUT out[16];
PARTS:
// Put your code here:
}
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 64
Project 1
Given: Nand
Goal: Build the following gates:
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 65
Chip building materials (using Xor as an example)
Xor.cmp The contract:
a
a b out When running your Xor.hdl on
Xor out
0 0 0 the supplied Xor.tst,
b 0 1 1
your Xor.out should be the
1 0 1
outputs 1 if a != b 1 1 0
same as the supplied Xor.cmp
Xor.hdl Xor.tst
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 66
Project 1 Resources
www.nand2tetris.org
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 67
More resources
• Text editor (for writing your HDL files)
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 68
Hack chipset API
a
a out
b
And
in out
Not
a
out
b
Or out
Not
in out
a
out
And
b
b
CHIP Xor {
IN a, b;
OUT out;
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 69
Hack chipset API
Add16 (a= ,b= ,out= );
ALU (x= ,y= ,zx= ,nx= ,zy= ,ny= ,f= ,no= ,out= ,zr= ,ng= );
And16 (a= ,b= ,out= );
Mux8Way (a= ,b= ,c= ,d= ,e= ,f= ,g= ,h= ,sel= ,out= );
And (a= ,b= ,out= );
Mux (a= ,b= ,sel= ,out= );
Aregister (in= ,load= ,out= );
Nand (a= ,b= ,out= );
Bit (in= ,load= ,out= );
Not16 (in= ,out= );
CPU (inM= ,instruction= ,reset= ,outM= ,writeM= ,addressM= ,pc= );
Not (in= ,out= );
DFF (in= ,out= );
Or16 (a= ,b= ,out= );
DMux4Way (in= ,sel= ,a= ,b= ,c= ,d= );
Or8Way (in= ,out= );
DMux8Way (in= ,sel= ,a= ,b= ,c= ,d= ,e= ,f= ,g= ,h= );
Or (a= ,b= ,out= );
Dmux (in= ,sel= ,a= ,b= );
PC (in= ,load= ,inc= ,reset= ,out= );
Dregister (in= ,load= ,out= );
PCLoadLogic (cinstr= ,j1= ,j2= ,j3= ,load= ,inc= );
FullAdder (a= ,b= ,c= ,sum= ,carry= );
RAM16K (in= ,load= ,address= ,out= );
HalfAdder (a= ,b= ,sum= , carry= );
RAM4K (in= ,load= ,address= ,out= );
Inc16 (in= ,out= );
RAM512 (in= ,load= ,address= ,out= );
Keyboard (out= );
RAM64 (in= ,load= ,address= ,out= );
Memory (in= ,load= ,address= ,out= );
RAM8 (in= ,load= ,address= ,out= );
Mux16 (a= ,b= ,sel= ,out= );
Register (in= ,load= ,out= );
Mux4Way16 (a= ,b= ,c= ,d= ,sel= ,out= );
ROM32K (address= ,out= );
Mux8Way16 (a= ,b= ,c= ,d= ,e= ,f= ,g= ,h= ,sel= ,out= );
Screen (in= ,load= ,address= ,out= );
Xor (a= ,b= ,out= );
q This will cause the simulator to use the built-in chip implementation.
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 71
Best practice advice
• Try to implement the chips in the given order
• If you don’t implement some chips, you can still use them as chip-parts
in other chips (the built-in implementations will kick in)
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 72
Chapter 1: Boolean logic
• Boolean logic
• Hardware simulation
• Multi-bit buses
• Project 1 overview
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 73
From Nand to Tetris
Building a Modern Computer from First Principles
Chapter 1
Boolean Logic
These slides support chapter 1 of the book
The Elements of Computing Systems
By Noam Nisan and Shimon Schocken
MIT Press
Nand to Tetris / www.nand2tetris.org / Chapter 1 / Copyright © Noam Nisan and Shimon Schocken Slide 74