Professional Documents
Culture Documents
Lecture 02 Boolean Arithmetic
Lecture 02 Boolean Arithmetic
Lecture 02 Boolean Arithmetic
www.nand2tetris.org
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic 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 2: Boolean Arithmetic slide 2
Counting systems
0 0 000
1 1 001
2 10 010
3 11 011
(10011) two 1 2 4 0 2 3 0 2 2 1 21 1 2 0 19
n
( xn xn1 ...x0 ) b xi b i
i 0
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 4
Binary addition
0 0 0 1 1 1 1 1
1 0 0 1 + 1 0 1 1+
0 1 0 1 0 1 1 1
0 1 1 1 0 1 0 0 1 0
no overflow overflow
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 5
Representing negative numbers (4-bit system)
Proposed implementation:
Half adder: designed to add 2 bits
Full adder: designed to add 3 bits
Adder: designed to add two n-bit numbers.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 7
Half adder (designed to add 2 bits)
a b sum carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 8
Full adder (designed to add 3 bits)
a b c sum carry
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 9
n-bit Adder (designed to add two 16-bit numbers)
... 1 0 1 1 a
+
… 0 0 1 0 b
… 1 1 0 1 out
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 10
The ALU (of the Hack platform)
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 11
ALU logic (Hack platform)
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 12
The ALU in the CPU context (a sneak preview of the Hack platform)
c1,c2, … ,c6
D
D register
a
out
ALU
A
A register
A/M
Mux
RAM M
(selected
register)
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 13
Perspective
Combinational logic
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 14
Historical end-note: Leibnitz (1646-1716)