SlideShare a Scribd company logo
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 1
www.nand2tetris.org
Building a Modern Computer From First Principles
Boolean Arithmetic
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 2
Counting systems
quantity decimal binary 3quantity decimal binary 3quantity decimal binary 3quantity decimal binary 3----bit registerbit registerbit registerbit register
0 0 000
1 1 001
2 10 010
3 11 011
4 100 100
5 101 101
6 110 110
7 111 111
8 1000 overflow
9 1001 overflow
10 1010 overflow
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 3
Rationale
192121202021)10011( 01234
=⋅+⋅+⋅+⋅+⋅=two
i
n
i
ibnn bxxxx ⋅= ∑=
−
0
01 )...(
9038018013010019)9038( 0123
=⋅+⋅+⋅+⋅=ten
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 4
no overflow overflow
Algorithm: exactly the same as in decimal addition
Overflow (MSB carry) has to be dealt with.
Binary addition
Assuming a 4-bit system:
0 0 0 1
1 0 0 1
0 1 0 1
0 1 1 1 0
++++
1 1 1 1
1 0 1 1
0 1 1 1
1 0 0 1 0
++++
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 5
Representing negative numbers (4-bit system)
The codes of all positive numbers
begin with a “0”
The codes of all negative numbers
begin with a “1“
To convert a number:
leave all trailing 0’s and first 1 intact,
and flip all the remaining bits
0 0000
1 0001 1111 -1
2 0010 1110 -2
3 0011 1101 -3
4 0100 1100 -4
5 0101 1011 -5
6 0110 1010 -6
7 0111 1001 -7
1000 -8
Example: 2 - 5 = 2 + (-5) = 0 0 1 0
+ 1 0 1 1
1 1 0 1 = -3
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 6
Building an Adder chip
Adder: a chip designed to add two integers
Proposed implementation:
Half adder: designed to add 2 bits
Full adder: designed to add 3 bits
Adder: designed to add two n-bit numbers.
out
a
16
16-bit
adder
b
16
16
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 7
Half adder (designed to add 2 bits)
Implementation: based on two gates that you’ve seen before.
half
adder
a sum
b carry
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)
Implementation: can be based on half-adder gates.
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
fu ll
ad d er
a
sum
b
carry
c
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)
Implementation: array of full-adder gates.
out
a
16
16-bit
adder
b
16
16
... 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)
half
adder
a sum
b carry
full
ad der
a
sum
b
carry
c
out
x
16
16-bit
adder
y
16
16
zx no
zr
nx zy ny f
ALU
ng
16 bits
16 bits
x
y 16 bits
out
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
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 11
ALU logic (Hack platform)
Implementation: build a logic gate architecture
that “executes” the control bit “instructions”:
if zx==1 then set x to 0 (bit-wise), etc.
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)
ALU
Mux
D
out
A/M
a
D register
A register
A
M
c1,c2, … ,c6
RAM
(selected
register)
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 13
Perspective
Combinational logic
Our adder design is very basic: no parallelism
It pays to optimize adders
Our ALU is also very basic: no multiplication, no division
Where is the seat of more advanced math operations?
a typical hardware/software tradeoff.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 14
Historical end-note: Leibnitz (1646-1716)
“The binary system may be used in place of the decimal system;
express all numbers by unity and by nothing”
1679: built a mechanical calculator (+, -, *, /)
CHALLENGE: “All who are occupied with the
reading or writing of scientific literature have
assuredly very often felt the want of a common
scientific language, and regretted the great loss of
time and trouble caused by the multiplicity of
languages employed in scientific literature:
SOLUTION: “Characteristica Universalis”: a
universal, formal, and decidable language of
reasoning
The dream’s end: Turing and Gödel in 1930’s.
Leibniz’s medallion
for the Duke of Brunswick

More Related Content

What's hot

Lecture 11 compiler ii
Lecture 11 compiler iiLecture 11 compiler ii
Lecture 11 compiler ii
鍾誠 陳鍾誠
 
Lecture 09 high level language
Lecture 09 high level languageLecture 09 high level language
Lecture 09 high level language
鍾誠 陳鍾誠
 
Lecture 08 virtual machine ii
Lecture 08 virtual machine iiLecture 08 virtual machine ii
Lecture 08 virtual machine ii
鍾誠 陳鍾誠
 
Lecture 07 virtual machine i
Lecture 07 virtual machine iLecture 07 virtual machine i
Lecture 07 virtual machine i
鍾誠 陳鍾誠
 
Lecture 10 compiler i
Lecture 10 compiler iLecture 10 compiler i
Lecture 10 compiler i
鍾誠 陳鍾誠
 
nand2tetris 舊版投影片 -- 第四章 機器語言
nand2tetris 舊版投影片 -- 第四章 機器語言nand2tetris 舊版投影片 -- 第四章 機器語言
nand2tetris 舊版投影片 -- 第四章 機器語言
鍾誠 陳鍾誠
 
Lecture 06 assembler
Lecture 06 assemblerLecture 06 assembler
Lecture 06 assembler
鍾誠 陳鍾誠
 
Machine language
Machine languageMachine language
Machine language
鍾誠 陳鍾誠
 
Chapter#4
Chapter#4Chapter#4
Computer organiztion2
Computer organiztion2Computer organiztion2
Computer organiztion2Umang Gupta
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
IIUM
 
Paper Ball
Paper BallPaper Ball
Paper Ball
lucas34990
 
tic-tac-toe: Game playing
 tic-tac-toe: Game playing tic-tac-toe: Game playing
tic-tac-toe: Game playing
kalpana Manudhane
 
Tic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmTic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max Algorithm
Ujjawal Poudel
 
Unit 2 module-2
Unit 2 module-2Unit 2 module-2
Unit 2 module-2
praveenabollyjoshi
 
Sequential and combinational alu
Sequential and combinational alu Sequential and combinational alu
Sequential and combinational alu Piyush Rochwani
 
Ceng232 Decoder Multiplexer Adder
Ceng232 Decoder Multiplexer AdderCeng232 Decoder Multiplexer Adder
Ceng232 Decoder Multiplexer Adder
gueste731a4
 
System design using HDL - Module 3
System design using HDL - Module 3System design using HDL - Module 3
System design using HDL - Module 3
Aravinda Koithyar
 
FLASHBRAIN report
FLASHBRAIN reportFLASHBRAIN report
FLASHBRAIN reportDaniel Han
 

What's hot (20)

Lecture 11 compiler ii
Lecture 11 compiler iiLecture 11 compiler ii
Lecture 11 compiler ii
 
Lecture 09 high level language
Lecture 09 high level languageLecture 09 high level language
Lecture 09 high level language
 
Lecture 08 virtual machine ii
Lecture 08 virtual machine iiLecture 08 virtual machine ii
Lecture 08 virtual machine ii
 
Lecture 07 virtual machine i
Lecture 07 virtual machine iLecture 07 virtual machine i
Lecture 07 virtual machine i
 
Lecture 10 compiler i
Lecture 10 compiler iLecture 10 compiler i
Lecture 10 compiler i
 
nand2tetris 舊版投影片 -- 第四章 機器語言
nand2tetris 舊版投影片 -- 第四章 機器語言nand2tetris 舊版投影片 -- 第四章 機器語言
nand2tetris 舊版投影片 -- 第四章 機器語言
 
Lecture 06 assembler
Lecture 06 assemblerLecture 06 assembler
Lecture 06 assembler
 
Machine language
Machine languageMachine language
Machine language
 
Chapter#4
Chapter#4Chapter#4
Chapter#4
 
Matlab workshop
Matlab workshopMatlab workshop
Matlab workshop
 
Computer organiztion2
Computer organiztion2Computer organiztion2
Computer organiztion2
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
 
Paper Ball
Paper BallPaper Ball
Paper Ball
 
tic-tac-toe: Game playing
 tic-tac-toe: Game playing tic-tac-toe: Game playing
tic-tac-toe: Game playing
 
Tic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmTic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max Algorithm
 
Unit 2 module-2
Unit 2 module-2Unit 2 module-2
Unit 2 module-2
 
Sequential and combinational alu
Sequential and combinational alu Sequential and combinational alu
Sequential and combinational alu
 
Ceng232 Decoder Multiplexer Adder
Ceng232 Decoder Multiplexer AdderCeng232 Decoder Multiplexer Adder
Ceng232 Decoder Multiplexer Adder
 
System design using HDL - Module 3
System design using HDL - Module 3System design using HDL - Module 3
System design using HDL - Module 3
 
FLASHBRAIN report
FLASHBRAIN reportFLASHBRAIN report
FLASHBRAIN report
 

Similar to nand2tetris 舊版投影片 -- 第二章 布林算術

lecture 02 Boolean arithmetic.ppt
lecture 02 Boolean arithmetic.pptlecture 02 Boolean arithmetic.ppt
lecture 02 Boolean arithmetic.ppt
zorogoh2
 
Computer organiztion3
Computer organiztion3Computer organiztion3
Computer organiztion3Umang Gupta
 
Binary parallel adder, decimal adder
Binary parallel adder, decimal adderBinary parallel adder, decimal adder
Binary parallel adder, decimal adder
shahzad ali
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
vishnu973656
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
Rvishnupriya2
 
Adapted from Harris & Harris Digital Design and Computer Arch.docx
Adapted from Harris & Harris Digital Design and Computer Arch.docxAdapted from Harris & Harris Digital Design and Computer Arch.docx
Adapted from Harris & Harris Digital Design and Computer Arch.docx
nettletondevon
 
Time series predictions using LSTMs
Time series predictions using LSTMsTime series predictions using LSTMs
Time series predictions using LSTMs
Setu Chokshi
 
eel6935_ch2.pdf
eel6935_ch2.pdfeel6935_ch2.pdf
eel6935_ch2.pdf
Sambasiva62
 
COA-Unit 1 Introduction.pptx
COA-Unit 1 Introduction.pptxCOA-Unit 1 Introduction.pptx
COA-Unit 1 Introduction.pptx
OmGadekar2
 
Class 26: Objectifying Objects
Class 26: Objectifying ObjectsClass 26: Objectifying Objects
Class 26: Objectifying Objects
David Evans
 
Digit recognizer by convolutional neural network
Digit recognizer by convolutional neural networkDigit recognizer by convolutional neural network
Digit recognizer by convolutional neural network
Ding Li
 
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Julien Le Dem
 
Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Cloudera, Inc.
 
Video lectures for bba
Video lectures for bbaVideo lectures for bba
Video lectures for bba
Edhole.com
 
02 combinational logic
02 combinational logic02 combinational logic
02 combinational logic
Zainab Noor
 
chapter3 (2).pdf
chapter3 (2).pdfchapter3 (2).pdf
chapter3 (2).pdf
luispinuer1
 
Probabilistic data structures. Part 3. Frequency
Probabilistic data structures. Part 3. FrequencyProbabilistic data structures. Part 3. Frequency
Probabilistic data structures. Part 3. Frequency
Andrii Gakhov
 
Chapter1.ppt
Chapter1.pptChapter1.ppt
Chapter1.ppt
PravinPrajapati53
 

Similar to nand2tetris 舊版投影片 -- 第二章 布林算術 (20)

lecture 02 Boolean arithmetic.ppt
lecture 02 Boolean arithmetic.pptlecture 02 Boolean arithmetic.ppt
lecture 02 Boolean arithmetic.ppt
 
Computer organiztion3
Computer organiztion3Computer organiztion3
Computer organiztion3
 
Binary parallel adder, decimal adder
Binary parallel adder, decimal adderBinary parallel adder, decimal adder
Binary parallel adder, decimal adder
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
 
Adapted from Harris & Harris Digital Design and Computer Arch.docx
Adapted from Harris & Harris Digital Design and Computer Arch.docxAdapted from Harris & Harris Digital Design and Computer Arch.docx
Adapted from Harris & Harris Digital Design and Computer Arch.docx
 
Time series predictions using LSTMs
Time series predictions using LSTMsTime series predictions using LSTMs
Time series predictions using LSTMs
 
Chapter1
Chapter1Chapter1
Chapter1
 
eel6935_ch2.pdf
eel6935_ch2.pdfeel6935_ch2.pdf
eel6935_ch2.pdf
 
COA-Unit 1 Introduction.pptx
COA-Unit 1 Introduction.pptxCOA-Unit 1 Introduction.pptx
COA-Unit 1 Introduction.pptx
 
Class 26: Objectifying Objects
Class 26: Objectifying ObjectsClass 26: Objectifying Objects
Class 26: Objectifying Objects
 
Sortingnetworks
SortingnetworksSortingnetworks
Sortingnetworks
 
Digit recognizer by convolutional neural network
Digit recognizer by convolutional neural networkDigit recognizer by convolutional neural network
Digit recognizer by convolutional neural network
 
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
 
Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0
 
Video lectures for bba
Video lectures for bbaVideo lectures for bba
Video lectures for bba
 
02 combinational logic
02 combinational logic02 combinational logic
02 combinational logic
 
chapter3 (2).pdf
chapter3 (2).pdfchapter3 (2).pdf
chapter3 (2).pdf
 
Probabilistic data structures. Part 3. Frequency
Probabilistic data structures. Part 3. FrequencyProbabilistic data structures. Part 3. Frequency
Probabilistic data structures. Part 3. Frequency
 
Chapter1.ppt
Chapter1.pptChapter1.ppt
Chapter1.ppt
 

More from 鍾誠 陳鍾誠

用十分鐘瞭解 新竹科學園區的發展史
用十分鐘瞭解  新竹科學園區的發展史用十分鐘瞭解  新竹科學園區的發展史
用十分鐘瞭解 新竹科學園區的發展史
鍾誠 陳鍾誠
 
用十分鐘搞懂 λ-Calculus
用十分鐘搞懂 λ-Calculus用十分鐘搞懂 λ-Calculus
用十分鐘搞懂 λ-Calculus
鍾誠 陳鍾誠
 
交⼤資訊⼯程學系備審資料 ⾱詠祥
交⼤資訊⼯程學系備審資料 ⾱詠祥交⼤資訊⼯程學系備審資料 ⾱詠祥
交⼤資訊⼯程學系備審資料 ⾱詠祥
鍾誠 陳鍾誠
 
smallpt: Global Illumination in 99 lines of C++
smallpt:  Global Illumination in 99 lines of C++smallpt:  Global Illumination in 99 lines of C++
smallpt: Global Illumination in 99 lines of C++
鍾誠 陳鍾誠
 
西洋史 (你或許不知道但卻影響現代教育的那些事)
西洋史  (你或許不知道但卻影響現代教育的那些事)西洋史  (你或許不知道但卻影響現代教育的那些事)
西洋史 (你或許不知道但卻影響現代教育的那些事)
鍾誠 陳鍾誠
 
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
鍾誠 陳鍾誠
 
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
鍾誠 陳鍾誠
 
梯度下降法 (隱藏在深度學習背後的演算法) -- 十分鐘系列
梯度下降法  (隱藏在深度學習背後的演算法) -- 十分鐘系列梯度下降法  (隱藏在深度學習背後的演算法) -- 十分鐘系列
梯度下降法 (隱藏在深度學習背後的演算法) -- 十分鐘系列
鍾誠 陳鍾誠
 
用十分鐘理解 《微分方程》
用十分鐘理解  《微分方程》用十分鐘理解  《微分方程》
用十分鐘理解 《微分方程》
鍾誠 陳鍾誠
 
系統程式 -- 前言
系統程式 -- 前言系統程式 -- 前言
系統程式 -- 前言
鍾誠 陳鍾誠
 
系統程式 -- 附錄
系統程式 -- 附錄系統程式 -- 附錄
系統程式 -- 附錄
鍾誠 陳鍾誠
 
系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作
鍾誠 陳鍾誠
 
系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統
鍾誠 陳鍾誠
 
系統程式 -- 第 10 章 作業系統
系統程式 -- 第 10 章 作業系統系統程式 -- 第 10 章 作業系統
系統程式 -- 第 10 章 作業系統
鍾誠 陳鍾誠
 
系統程式 -- 第 9 章 虛擬機器
系統程式 -- 第 9 章 虛擬機器系統程式 -- 第 9 章 虛擬機器
系統程式 -- 第 9 章 虛擬機器
鍾誠 陳鍾誠
 
系統程式 -- 第 8 章 編譯器
系統程式 -- 第 8 章 編譯器系統程式 -- 第 8 章 編譯器
系統程式 -- 第 8 章 編譯器
鍾誠 陳鍾誠
 
系統程式 -- 第 7 章 高階語言
系統程式 -- 第 7 章 高階語言系統程式 -- 第 7 章 高階語言
系統程式 -- 第 7 章 高階語言
鍾誠 陳鍾誠
 
系統程式 -- 第 6 章 巨集處理器
系統程式 -- 第 6 章 巨集處理器系統程式 -- 第 6 章 巨集處理器
系統程式 -- 第 6 章 巨集處理器
鍾誠 陳鍾誠
 
系統程式 -- 第 5 章 連結與載入
系統程式 -- 第 5 章 連結與載入系統程式 -- 第 5 章 連結與載入
系統程式 -- 第 5 章 連結與載入
鍾誠 陳鍾誠
 
系統程式 -- 第 4 章 組譯器
系統程式 -- 第 4 章 組譯器系統程式 -- 第 4 章 組譯器
系統程式 -- 第 4 章 組譯器
鍾誠 陳鍾誠
 

More from 鍾誠 陳鍾誠 (20)

用十分鐘瞭解 新竹科學園區的發展史
用十分鐘瞭解  新竹科學園區的發展史用十分鐘瞭解  新竹科學園區的發展史
用十分鐘瞭解 新竹科學園區的發展史
 
用十分鐘搞懂 λ-Calculus
用十分鐘搞懂 λ-Calculus用十分鐘搞懂 λ-Calculus
用十分鐘搞懂 λ-Calculus
 
交⼤資訊⼯程學系備審資料 ⾱詠祥
交⼤資訊⼯程學系備審資料 ⾱詠祥交⼤資訊⼯程學系備審資料 ⾱詠祥
交⼤資訊⼯程學系備審資料 ⾱詠祥
 
smallpt: Global Illumination in 99 lines of C++
smallpt:  Global Illumination in 99 lines of C++smallpt:  Global Illumination in 99 lines of C++
smallpt: Global Illumination in 99 lines of C++
 
西洋史 (你或許不知道但卻影響現代教育的那些事)
西洋史  (你或許不知道但卻影響現代教育的那些事)西洋史  (你或許不知道但卻影響現代教育的那些事)
西洋史 (你或許不知道但卻影響現代教育的那些事)
 
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
 
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
 
梯度下降法 (隱藏在深度學習背後的演算法) -- 十分鐘系列
梯度下降法  (隱藏在深度學習背後的演算法) -- 十分鐘系列梯度下降法  (隱藏在深度學習背後的演算法) -- 十分鐘系列
梯度下降法 (隱藏在深度學習背後的演算法) -- 十分鐘系列
 
用十分鐘理解 《微分方程》
用十分鐘理解  《微分方程》用十分鐘理解  《微分方程》
用十分鐘理解 《微分方程》
 
系統程式 -- 前言
系統程式 -- 前言系統程式 -- 前言
系統程式 -- 前言
 
系統程式 -- 附錄
系統程式 -- 附錄系統程式 -- 附錄
系統程式 -- 附錄
 
系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作
 
系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統
 
系統程式 -- 第 10 章 作業系統
系統程式 -- 第 10 章 作業系統系統程式 -- 第 10 章 作業系統
系統程式 -- 第 10 章 作業系統
 
系統程式 -- 第 9 章 虛擬機器
系統程式 -- 第 9 章 虛擬機器系統程式 -- 第 9 章 虛擬機器
系統程式 -- 第 9 章 虛擬機器
 
系統程式 -- 第 8 章 編譯器
系統程式 -- 第 8 章 編譯器系統程式 -- 第 8 章 編譯器
系統程式 -- 第 8 章 編譯器
 
系統程式 -- 第 7 章 高階語言
系統程式 -- 第 7 章 高階語言系統程式 -- 第 7 章 高階語言
系統程式 -- 第 7 章 高階語言
 
系統程式 -- 第 6 章 巨集處理器
系統程式 -- 第 6 章 巨集處理器系統程式 -- 第 6 章 巨集處理器
系統程式 -- 第 6 章 巨集處理器
 
系統程式 -- 第 5 章 連結與載入
系統程式 -- 第 5 章 連結與載入系統程式 -- 第 5 章 連結與載入
系統程式 -- 第 5 章 連結與載入
 
系統程式 -- 第 4 章 組譯器
系統程式 -- 第 4 章 組譯器系統程式 -- 第 4 章 組譯器
系統程式 -- 第 4 章 組譯器
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
ShivajiThube2
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 

nand2tetris 舊版投影片 -- 第二章 布林算術

  • 1. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 1 www.nand2tetris.org Building a Modern Computer From First Principles Boolean Arithmetic
  • 2. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 2 Counting systems quantity decimal binary 3quantity decimal binary 3quantity decimal binary 3quantity decimal binary 3----bit registerbit registerbit registerbit register 0 0 000 1 1 001 2 10 010 3 11 011 4 100 100 5 101 101 6 110 110 7 111 111 8 1000 overflow 9 1001 overflow 10 1010 overflow
  • 3. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 3 Rationale 192121202021)10011( 01234 =⋅+⋅+⋅+⋅+⋅=two i n i ibnn bxxxx ⋅= ∑= − 0 01 )...( 9038018013010019)9038( 0123 =⋅+⋅+⋅+⋅=ten
  • 4. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 4 no overflow overflow Algorithm: exactly the same as in decimal addition Overflow (MSB carry) has to be dealt with. Binary addition Assuming a 4-bit system: 0 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 ++++ 1 1 1 1 1 0 1 1 0 1 1 1 1 0 0 1 0 ++++
  • 5. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 5 Representing negative numbers (4-bit system) The codes of all positive numbers begin with a “0” The codes of all negative numbers begin with a “1“ To convert a number: leave all trailing 0’s and first 1 intact, and flip all the remaining bits 0 0000 1 0001 1111 -1 2 0010 1110 -2 3 0011 1101 -3 4 0100 1100 -4 5 0101 1011 -5 6 0110 1010 -6 7 0111 1001 -7 1000 -8 Example: 2 - 5 = 2 + (-5) = 0 0 1 0 + 1 0 1 1 1 1 0 1 = -3
  • 6. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 6 Building an Adder chip Adder: a chip designed to add two integers Proposed implementation: Half adder: designed to add 2 bits Full adder: designed to add 3 bits Adder: designed to add two n-bit numbers. out a 16 16-bit adder b 16 16
  • 7. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 7 Half adder (designed to add 2 bits) Implementation: based on two gates that you’ve seen before. half adder a sum b carry a b sum carry 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1
  • 8. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 8 Full adder (designed to add 3 bits) Implementation: can be based on half-adder gates. 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 fu ll ad d er a sum b carry c
  • 9. 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) Implementation: array of full-adder gates. out a 16 16-bit adder b 16 16 ... 1 0 1 1 a … 0 0 1 0 b … 1 1 0 1 out ++++
  • 10. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 10 The ALU (of the Hack platform) half adder a sum b carry full ad der a sum b carry c out x 16 16-bit adder y 16 16 zx no zr nx zy ny f ALU ng 16 bits 16 bits x y 16 bits out 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
  • 11. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 11 ALU logic (Hack platform) Implementation: build a logic gate architecture that “executes” the control bit “instructions”: if zx==1 then set x to 0 (bit-wise), etc.
  • 12. 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) ALU Mux D out A/M a D register A register A M c1,c2, … ,c6 RAM (selected register)
  • 13. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 13 Perspective Combinational logic Our adder design is very basic: no parallelism It pays to optimize adders Our ALU is also very basic: no multiplication, no division Where is the seat of more advanced math operations? a typical hardware/software tradeoff.
  • 14. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 14 Historical end-note: Leibnitz (1646-1716) “The binary system may be used in place of the decimal system; express all numbers by unity and by nothing” 1679: built a mechanical calculator (+, -, *, /) CHALLENGE: “All who are occupied with the reading or writing of scientific literature have assuredly very often felt the want of a common scientific language, and regretted the great loss of time and trouble caused by the multiplicity of languages employed in scientific literature: SOLUTION: “Characteristica Universalis”: a universal, formal, and decidable language of reasoning The dream’s end: Turing and Gödel in 1930’s. Leibniz’s medallion for the Duke of Brunswick