lecture 01 Boolean logic

Building a Modern Computer From First Principles
www.nand2tetris.org

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 1

Boolean algebra
xx
00
11

xx
00
00
11
11

x

y


z

f ( x, y , z ) = ( x + y ) z

0
0
0
0
1
1
1
1

0
0
1
1
0
0

1
1

0
1
0
1
0
1
0
1

0
0
1
0
1
0
1
0


"!

Not(x)
Not(x)
11
00

yy
00
11
00
11

Or(x,y)
Or(x,y)
00
11
11
11


xx
00
00
11
11

yy
00
11
00
11

And(x,y)
And(x,y)
00
00
00
11


xx
00
00
11
11

yy
00
11
00
11

Nand(x,y)
Nand(x,y)
11
11
11
00

!

#

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 2

All Boolean functions of 2 variables

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 3

Boolean algebra
$!

Nand(a,b), false

%
Not(a) = Nand(a,a)
true = Not(false)

And(a,b) = Not(Nand(a,b))

$

&'&()&'*+
,

-

.

Or(a,b) = Not(And(Not(a),Not(b)))
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 4

Gate logic
$


/

"

-

0

1

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

0#
slide 5

Gate logic

a
Xor


out

b
a

b

out

0
0
1
1

0
1
0
1


0
1
1
0

&4&*)566&

,

7
0

-

.

a
And
Not
Or


out

Not
And

b

2

3

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 6

Circuit implementations
a
a

b
a
0
0
1
1

AND gate

b
0
1
0
1

out
0
0
0
1

b
OR gate

power supply

b
0
1
0
1

out
0
1
1
1

power supply

out

a

b
a
0
0
0
0
1
1
1
1

a
0
0
1
1

b
0
0
1
1
0
0
1
1

out

c

c out
0 0
1 0
0 0
1 0
0 0
1 0
0 0
1 1

a
AND

b

AND (a,b,c)

out
AND

c

out

8

9

!

!

#

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 7

Project 1: elementary logic gates
aa
00
00
11
11

Nand(a,b), false

bb
00
11
00
11

Nand(a,b)
Nand(a,b)
11
11
11
00

Not(a) = ...
true = ...
: %

And(a,b) = ...

&5

;

<

Or(a,b) = ...

=

Mux(a,b,sel) = ...

=

" # ) &5

#

!
>
#

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 8

Multiplexer

aa
00
00
00
00
11
11
11
11

bb sel
sel
00 00
00 11
11 00
11 11
00 00
00 11
11 00
11 11

out
out
00
00
00
11
11
00
11
11

sel
sel out
out
00
aa
11
bb

a
Mux

out

b

sel

?

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

#

slide 9

Example: Building an And gate
-

#

a

And

b

out

aa
00
00
11
11

%
.hdl
.out

bb out
out
00 00
11 00
00 00
11 11

.tst

.cmp.

#
CHIP
CHIP And
And
{{ IN
IN a,
a, b;
b;
OUT
out;
OUT out;
//
// implementation
implementation missing
missing
}}

#
load
load And.hdl,
And.hdl,
output-file
output-file And.out,
And.out,
compare-to
compare-to And.cmp,
And.cmp,
output-list
output-list aa bb out;
out;
set
set aa 0,set
0,set bb 0,eval,output;
0,eval,output;
set
a
0,set
b
1,eval,output;
set a 0,set b 1,eval,output;
set
set aa 1,set
1,set bb 0,eval,output;
0,eval,output;
set
set aa 1,
1, set
set bb 1,
1, eval,
eval, output;
output;

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 10

Building an And gate
3&

0

3 3&

a

And

b

out

#
CHIP
CHIP And
And
{{ IN
IN a,
a, b;
b;
OUT
out;
OUT out;
//
// implementation
implementation missing
missing
}}

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 11

Building an And gate
3

a
out
b

#
CHIP
CHIP And
And
{{ IN
IN a,
a, b;
b;
OUT
out;
OUT out;
//
// implementation
implementation missing
missing
}}

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 12

Building an And gate
3

a

a
Nand

b

out

x

in

Not

out

out

b

#
CHIP
CHIP And
And
{{ IN
IN a,
a, b;
b;
OUT
out;
OUT out;
//
// implementation
implementation missing
missing
}}

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 13

Building an And gate
3

a

a
NAND

b

out

x

in

NOT

out

out

b

#
CHIP
CHIP And
And
{{ IN
IN a,
a, b;
b;
OUT
out;
OUT out;
Nand(a
Nand(a == a,
a,
bb == b,
b,
out
=
out = x);
x);
Not(in
Not(in == x,
x, out
out == out)
out)
}}

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 14

Hardware simulator (demonstrating Xor gate construction)

HDL
program

test
script

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 15

Hardware simulator

HDL
program

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 16

Hardware simulator

HDL
program
output
file

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 17

Project materials: www.nand2tetris.org

?

@

&0

And.hdl
And.tst
And.cmp

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 18

Project 1 tips
7

A-

B 0

>C

$

>

0
0

B ? @
D

&

C

6
#

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 19

Perspective
"
=

"

!

9

? B

a

E

b

and

c

F !
G

>

..
.

or

f(a,b,c)

and

$

<

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 20

End notes: Canonical representation
%

"

!

!
0

0# =
0

0
Truth table of the "suspect" function

Canonical form:

#

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 21

End notes: Canonical representation (cont.)
s (a, m, w) = a ⋅ ( m + w)
a
or

s

m
w

and

s ( a, m, w) = a m w + a m w + a m w
a
m

and

w

and

or

s

and

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 22

End notes: Programmable Logic Device for 3-way functions
a
legend:
active fuse

and

b

blown fuse

c

8 and terms
connected to the
same 3 inputs

..
.
and

or

f(a,b,c)

single or term
connected to the
outputs of 8 and terms

_
_ _
PLD implementation of f(a,b,c)= a b c + a b c
(the on/off states of the fuses determine which gates participate in the computation)

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 23

End notes: universal building blocks, unique topology
a
b

and

c

..
.

or

f(a,b,c)

and

Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 1: Boolean Logic

slide 24