https://www.nand2tetris.org/

https://www.coursera.org/learn/build-a-computer

## Chapter 1 布尔逻辑

### Part 1：课程回顾

#### Bool逻辑与Bool函数

$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

| $x$ | $y$ | $z$ | $f$ |
| —— | —— | —— | —— |
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |

##### 引理2

Nand门输入输出关系如下

$x$ $y$ $\text{Nand}(x,y)$
$0$ $0$ $1$
$0$ $1$ $1$
$1$ $0$ $1$
$1$ $1$ $0$

### Part 2：项目

#### Nand

Nand门输入输出关系如下

$a$ $b$ $\text{Nand}(a,b)$
$0$ $0$ $1$
$0$ $1$ $1$
$1$ $0$ $1$
$1$ $1$ $0$

#### Not

$a$ $a$ $\text{Nand}(a,a)$
$0$ $0$ $1$
$0$ $0$ $1$
$1$ $1$ $0$
$1$ $1$ $0$

#### And

$\text{Nand}(a,b)$的特点，不难发现有

#### XOR

XOR门输入输出关系如下

$a$ $b$ $\text{XOR}(a,b)$
$0$ $0$ $0$
$0$ $1$ $1$
$1$ $0$ $1$
$1$ $1$ $0$

#### Mux

Mux是选择器，输入为$a,b,\text{sel}$

$\text{sel}$ $\text{out}$
$0$ $a$
$1$ $b$

#### DMux

DMux的作用如下：

• if (sel==0)
• {a,b}={in,0}
• else
• {a,b}={0,in}

$\text{in}$ $\text{sel}$ $\text{Not}(\text{sel})$ $a$ $b$
$0$ $0$ $1$ $0$ $0$
$0$ $1$ $0$ $0$ $0$
$1$ $0$ $1$ $1$ $0$
$1$ $1$ $0$ $0$ $1$

#### Mux4Way16

Mux4Way16的作用如下

• out = a if sel == 00
• b if sel == 01
• c if sel == 10
• d if sel == 11

（备注，$\text{sel}[0]$为最右边的数字）

#### Mux8Way16

Mux8Way16和Mux4Way16作用类似，是对$8$个输入做选择，先根据$\text{sel}[0..1]$对前四个以及后四个做选择，然后根据$\text{sel}[2]$在第一步的结果之间做选择。

#### DMux4Way

• 4-way demultiplexor:
• {a, b, c, d} =
• {in, 0, 0, 0} if sel == 00
• {0, in, 0, 0} if sel == 01
• {0, 0, in, 0} if sel == 10
• {0, 0, 0, in} if sel == 11

{a1, b1, c1, d1} =

• {in, 0, in, 0} if sel == 00
• {0, in, 0, in} if sel == 01
• {in, 0, in, 0} if sel == 10
• {0, in, 0, in} if sel == 11

{a, b, c, d} =

• {in, 0, 0, 0} if sel == 00
• {0, in, 0, 0} if sel == 01
• {0, 0, in, 0} if sel == 10
• {0, 0, 0, in} if sel == 11