Professional Documents
Culture Documents
Lecture 01 Boolean Logic
Lecture 01 Boolean Logic
www.nand2tetris.org
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 1
Usage and Copyright Notice:
This presentation contains lecture materials that accompany the textbook “The Elements of
Computing Systems” by Noam Nisan & Shimon Schocken, MIT Press, 2005.
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 non-
commercial purposes.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 2
Boolean algebra
Some elementary Boolean functions: x Not(x) x y And(x,y)
0 1 0 0 0
Not(x) 1 0 0 1 0
1 0 0
And(x,y) 1 1 1
Or(x,y)
Nand(x,y) x y Or(x,y) x y Nand(x,y)
0 0 0 0 0 1
0 1 1 0 1 1
Boolean functions: 1 0 1 1 0 1
1 1 1 1 1 0
x y z f ( x, y , z ) ( x y ) z
0 0 0 0
0 0 1 0 A Boolean function can be expressed using a
0 1 0 1 functional expression or a truth table expression
0 1 1 0
1 0 0 1 Important observation:
1 0 1 0 Every Boolean function can be expressed using
1 1 0 1 And, Or, Not.
1 1 1 0
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 3
All Boolean functions of 2 variables
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 4
Boolean algebra
We can build:
Not(a) = Nand(a,a)
Or(a,b) = Not(And(Not(a),Not(b)))
Xor(a,b) = Or(And(a,Not(b)),And(Not(a),b)))
Etc.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 5
Gate logic
Elementary gates:
Composite gates:
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 6
Gate logic
Interface
a
Xor out
b
Claude Shannon, 1916-2001
a b out (“Symbolic Analysis of Relay and
Switching Circuits” )
0 0 0
0 1 1
1 0 1
1 1 0 Implementation
Xor(a,b) = Or(And(a,Not(b)),And(Not(a),b)))
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 7
Circuit implementations
a b Nand(a,b)
Given: Nand(a,b), false 0 0 1
0 1 1
1 0 1
Build: 1 1 0
Not(a) = ...
true = ...
a b sel out
sel out
0 0 0 0
0 a
0 0 1 0
1 b
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 10
Example: Building an And gate
Contract:
And.cmp
a b out When running your
0 0 0
0 1 0
.hdl on our .tst,
1 0 0 your .out should
1 1 1 be the same as
our .cmp.
And.hdl And.tst
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 11
Building an And gate
And.hdl
CHIP And
{ IN a, b;
OUT out;
// implementation missing
}
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 12
Building an And gate
And.hdl
CHIP And
{ IN a, b;
OUT out;
// implementation missing
}
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 13
Building an And gate
And.hdl
CHIP And
{ IN a, b;
OUT out;
// implementation missing
}
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 14
Building an And gate
And.hdl
CHIP And
{ IN a, b;
OUT out;
Nand(a = a,
b = b,
out = x);
Not(in = x, out = out)
}
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 15
Hardware simulator (demonstrating Xor gate construction)
test
HDL
script
program
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 16
Hardware simulator
HDL
program
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 17
Hardware simulator
HDL
program
output
file
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 18
Project materials: www.nand2tetris.org
And.hdl ,
And.tst ,
And.cmp files
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 19
Project 1 tips
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 20
Perspective
Mass production
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 21
End notes: Canonical representation
Whodunit story: Each suspect may or may not have an alibi ( a), a motivation to
commit the crime (m), and a relationship to the weapon found in the scene
of the crime (w). The police decides to focus attention only on suspects
for whom the proposition Not(a) And (m Or w) is true.
s (a, m, w) a (m w)
s (a, m, w) a m w a m w a m w
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 23
End notes: Programmable Logic Device for 3-way functions
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 24
End notes: universal building blocks, unique topology
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic slide 25