Skip to content

Commit c3f4b73

Browse files
committed
update character1
1 parent 32b629c commit c3f4b73

19 files changed

+662
-0
lines changed

Documents/Code/.DS_Store

2 KB
Binary file not shown.

Documents/Code/01/.DS_Store

6 KB
Binary file not shown.

Documents/Code/01/And.hdl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file is part of www.nand2tetris.org
2+
// and the book "The Elements of Computing Systems"
3+
// by Nisan and Schocken, MIT Press.
4+
// File name: projects/01/And.hdl
5+
6+
/**
7+
* And gate:
8+
* out = 1 if (a == 1 and b == 1)
9+
* 0 otherwise
10+
*/
11+
12+
CHIP And {
13+
IN a, b;
14+
OUT out;
15+
16+
PARTS:
17+
// Put your code here:
18+
// maybe successful, but it seems that I cannot take the constructed chips?
19+
Nand(a = a, b = b, out = outab);
20+
Not(in = outab, out = out);
21+
}
22+

Documents/Code/01/And16.hdl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// This file is part of www.nand2tetris.org
2+
// and the book "The Elements of Computing Systems"
3+
// by Nisan and Schocken, MIT Press.
4+
// File name: projects/01/And16.hdl
5+
6+
/**
7+
* 16-bit bitwise And:
8+
* for i = 0..15: out[i] = (a[i] and b[i])
9+
*/
10+
11+
CHIP And16 {
12+
IN a[16], b[16];
13+
OUT out[16];
14+
15+
PARTS:
16+
// Put your code here:
17+
And(a = a[0], b = b[0], out = out[0]);
18+
And(a = a[1], b = b[1], out = out[1]);
19+
And(a = a[2], b = b[2], out = out[2]);
20+
And(a = a[3],b = b[3], out = out[3]);
21+
And(a = a[4], b = b[4], out = out[4]);
22+
And(a = a[5], b = b[5], out = out[5]);
23+
And(a = a[6], b = b[6], out = out[6]);
24+
And(a = a[7], b = b[7], out = out[7]);
25+
And(a = a[8], b = b[8], out = out[8]);
26+
And(a = a[9], b = b[9], out = out[9]);
27+
And(a = a[10], b = b[10], out = out[10]);
28+
And(a = a[11], b = b[11], out = out[11]);
29+
And(a = a[12], b = b[12], out = out[12]);
30+
And(a = a[13], b = b[13], out = out[13]);
31+
And(a = a[14], b = b[14], out = out[14]);
32+
And(a = a[15], b = b[15], out = out[15]);
33+
}

Documents/Code/01/And16to1.hdl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CHIP And16to1 {
2+
IN a, b[16];
3+
OUT out[16];
4+
5+
PARTS:
6+
// Put your code here:
7+
And(a = a, b = true, out = out[0]);
8+
And(a = a, b = true, out = out[1]);
9+
And(a = a, b = true, out = out[2]);
10+
And(a = a, b = true, out = out[3]);
11+
And(a = a, b = true, out = out[4]);
12+
And(a = a, b = true, out = out[5]);
13+
And(a = a, b = true, out = out[6]);
14+
And(a = a, b = true, out = out[7]);
15+
And(a = a, b = true, out = out[8]);
16+
And(a = a, b = true, out = out[9]);
17+
And(a = a, b = true, out = out[10]);
18+
And(a = a, b = true, out = out[11]);
19+
And(a = a, b = true, out = out[12]);
20+
And(a = a, b = true, out = out[13]);
21+
And(a = a, b = true, out = out[14]);
22+
And(a = a, b = true, out = out[15]);
23+
}
24+

Documents/Code/01/DMux.hdl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This file is part of www.nand2tetris.org
2+
// and the book "The Elements of Computing Systems"
3+
// by Nisan and Schocken, MIT Press.
4+
// File name: projects/01/DMux.hdl
5+
6+
/**
7+
* Demultiplexor:
8+
* {a, b} = {in, 0} if sel == 0
9+
* {0, in} if sel == 1
10+
*/
11+
12+
CHIP DMux {
13+
IN in, sel;
14+
OUT a, b;
15+
16+
PARTS:
17+
// Put your code here:
18+
Not(in = sel, out = notsel);
19+
And(a = notsel, b = in, out = a);
20+
And(a = in, b = sel, out = b);
21+
}

Documents/Code/01/DMux4way.hdl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file is part of www.nand2tetris.org
2+
// and the book "The Elements of Computing Systems"
3+
// by Nisan and Schocken, MIT Press.
4+
// File name: projects/01/DMux4Way.hdl
5+
6+
/**
7+
* 4-way demultiplexor:
8+
* {a, b, c, d} = {in, 0, 0, 0} if sel == 00
9+
* {0, in, 0, 0} if sel == 01
10+
* {0, 0, in, 0} if sel == 10
11+
* {0, 0, 0, in} if sel == 11
12+
*/
13+
14+
CHIP DMux4Way {
15+
IN in, sel[2];
16+
OUT a, b, c, d;
17+
18+
PARTS:
19+
// Put your code here:
20+
Xor(a = true, b = sel[0], out = Xora1);
21+
Xor(a = true, b = sel[1], out = Xora2);
22+
Xor(a = false, b = sel[0], out = Xorb1);
23+
Xor(a = true, b = sel[1], out = Xorb2);
24+
Xor(a = true, b = sel[0], out = Xorc1);
25+
Xor(a = false, b = sel[1], out = Xorc2);
26+
Xor(a = false, b = sel[0], out = Xord1);
27+
Xor(a = false, b = sel[1], out = Xord2);
28+
And(a = Xora1, b = Xora2, out = Xor1);
29+
And(a = Xor1, b = in, out = a);
30+
And(a = Xorb1, b = Xorb2, out = Xor2);
31+
And(a = Xor2, b = in, out = b);
32+
And(a = Xorc1, b = Xorc2, out = Xor3);
33+
And(a = Xor3, b = in, out = c);
34+
And(a = Xord1, b = Xord2, out = Xor4);
35+
And(a = Xor4, b = in, out = d);
36+
}

Documents/Code/01/DMux8Way.hdl1

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// This file is part of www.nand2tetris.org
2+
// and the book "The Elements of Computing Systems"
3+
// by Nisan and Schocken, MIT Press.
4+
// File name: projects/01/DMux8Way.hdl
5+
6+
/**
7+
* 8-way demultiplexor:
8+
* {a, b, c, d, e, f, g, h} = {in, 0, 0, 0, 0, 0, 0, 0} if sel == 000
9+
* {0, in, 0, 0, 0, 0, 0, 0} if sel == 001
10+
* etc.
11+
* {0, 0, 0, 0, 0, 0, 0, in} if sel == 111
12+
*/
13+
14+
CHIP DMux8Way {
15+
IN in, sel[3];
16+
OUT a, b, c, d, e, f, g, h;
17+
18+
PARTS:
19+
// Put your code here:
20+
//a
21+
Xor(a = true, b = sel[0], out = Xora1);
22+
Xor(a = true, b = sel[1], out = Xora2);
23+
Xor(a = true, b = sel[2], out = Xora3);
24+
And(a = Xora1, b = Xora2, out = Xora4);
25+
And(a = Xora4, b = Xora3, out = And1);
26+
And(a = And1, b = in, out = a);
27+
//b
28+
Xor(a = false, b = sel[0], out = Xorb1);
29+
Xor(a = true, b = sel[1], out = Xorb2);
30+
Xor(a = true, b = sel[2], out = Xorb3);
31+
And(a = Xorb1, b = Xorb2, out = Xorb4);
32+
And(a = Xorb4, b = Xorb3, out = And2);
33+
And(a = And2, b = in, out = b);
34+
//c
35+
Xor(a = true, b = sel[0], out = Xorc1);
36+
Xor(a = false, b = sel[1], out = Xorc2);
37+
Xor(a = true, b = sel[2], out = Xorc3);
38+
And(a = Xorc1, b = Xorc2, out = Xorc4);
39+
And(a = Xorc4, b = Xorc3, out = And3);
40+
And(a = And3, b = in, out = c);
41+
//d
42+
Xor(a = false, b = sel[0], out = Xord1);
43+
Xor(a = false, b = sel[1], out = Xord2);
44+
Xor(a = true, b = sel[2], out = Xord3);
45+
And(a = Xord1, b = Xord2, out = Xord4);
46+
And(a = Xord4, b = Xord3, out = And4);
47+
And(a = And4, b = in, out = d);
48+
//e
49+
Xor(a = true, b = sel[0], out = Xore1);
50+
Xor(a = true, b = sel[1], out = Xore2);
51+
Xor(a = false, b = sel[2], out = Xore3);
52+
And(a = Xore1, b = Xore2, out = Xore4);
53+
And(a = Xore4, b = Xore3, out = And5);
54+
And(a = And5, b = in, out = e);
55+
//f
56+
Xor(a = false, b = sel[0], out = Xorf1);
57+
Xor(a = true, b = sel[1], out = Xorf2);
58+
Xor(a = false, b = sel[2], out = Xorf3);
59+
And(a = Xorf1, b = Xorf2, out = Xorf4);
60+
And(a = Xorf3, b = Xorf4, out = And6);
61+
And(a = And6, b = in, out = f);
62+
//g
63+
Xor(a = true, b = sel[0], out = Xorg1);
64+
Xor(a = false, b = sel[1], out = Xorg2);
65+
Xor(a = false, b = sel[2], out = Xorg3);
66+
And(a = Xorg1, b = Xorg2, out = Xorg4);
67+
And(a = Xorg4, b = Xorg3, out = And7);
68+
And(a = And7, b = in, out = g);
69+
//h
70+
Xor(a = false, b = sel[0], out = Xorh1);
71+
Xor(a = false, b = sel[1], out = Xorh2);
72+
Xor(a = false, b = sel[2], out = Xorh3);
73+
And(a = Xorh1, b = Xorh2, out = Xorh4);
74+
And(a = Xorh3, b = Xorh4, out = And8);
75+
And(a = And8, b = in, out = h);
76+
}

Documents/Code/01/Mux.hdl1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file is part of www.nand2tetris.org
2+
// and the book "The Elements of Computing Systems"
3+
// by Nisan and Schocken, MIT Press.
4+
// File name: projects/01/Mux.hdl
5+
6+
/**
7+
* Multiplexor:
8+
* out = a if sel == 0
9+
* b otherwise
10+
*/
11+
12+
CHIP Mux {
13+
IN a, b, sel;
14+
OUT out;
15+
16+
PARTS:
17+
// Put your code here:
18+
Not(in = sel, out = Notsel);
19+
And(a = a, b = Notsel, out = outaAndsel);
20+
And(a = b, b = sel, out = outaAndb);
21+
Or(a = outaAndsel, b = outaAndb, out = out);
22+
}

Documents/Code/01/Mux16.hdl1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This file is part of www.nand2tetris.org
2+
// and the book "The Elements of Computing Systems"
3+
// by Nisan and Schocken, MIT Press.
4+
// File name: projects/01/Mux16.hdl
5+
6+
/**
7+
* 16-bit multiplexor:
8+
* for i = 0..15 out[i] = a[i] if sel == 0
9+
* b[i] if sel == 1
10+
*/
11+
12+
CHIP Mux16 {
13+
IN a[16], b[16], sel;
14+
OUT out[16];
15+
16+
PARTS:
17+
// Put your code here:
18+
Mux(a = a[0], b = b[0], sel = sel, out = out[0]);
19+
Mux(a = a[1], b = b[1], sel = sel, out = out[1]);
20+
Mux(a = a[2], b = b[2], sel = sel, out = out[2]);
21+
Mux(a = a[3], b = b[3], sel = sel, out = out[3]);
22+
Mux(a = a[4], b = b[4], sel = sel, out = out[4]);
23+
Mux(a = a[5], b = b[5], sel = sel, out = out[5]);
24+
Mux(a = a[6], b = b[6], sel = sel, out = out[6]);
25+
Mux(a = a[7], b = b[7], sel = sel, out = out[7]);
26+
Mux(a = a[8], b = b[8], sel = sel, out = out[8]);
27+
Mux(a = a[9], b = b[9], sel = sel, out = out[9]);
28+
Mux(a = a[10], b = b[10], sel = sel, out = out[10]);
29+
Mux(a = a[11], b = b[11], sel = sel, out = out[11]);
30+
Mux(a = a[12], b = b[12], sel = sel, out = out[12]);
31+
Mux(a = a[13], b = b[13], sel = sel, out = out[13]);
32+
Mux(a = a[14], b = b[14], sel = sel, out = out[14]);
33+
Mux(a = a[15], b = b[15], sel = sel, out = out[15]);
34+
}

Documents/Code/01/Mux4way16.hdl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// This file is part of www.nand2tetris.org
2+
// and the book "The Elements of Computing Systems"
3+
// by Nisan and Schocken, MIT Press.
4+
// File name: projects/01/Mux4Way16.hdl
5+
6+
/**
7+
* 4-way 16-bit multiplexor:
8+
* out = a if sel == 00
9+
* b if sel == 01
10+
* c if sel == 10
11+
* d if sel == 11
12+
*/
13+
CHIP Mux4Way16 {
14+
15+
IN a[16], b[16], c[16], d[16], sel[2];
16+
17+
OUT out[16];
18+
19+
20+
21+
PARTS:
22+
23+
// Put your code here:
24+
// I can design another chips to satisfy my need.
25+
26+
27+
//a
28+
Xor(a = true, b = sel[0], out = Anda1);
29+
Xor(a = true, b = sel[1], out = Anda2);
30+
And(a = Anda1, b = Anda2, out = And1);
31+
And16to1(a = And1, b = true, out = cana);
32+
And16(a = a, b = cana, out = outa);
33+
//b
34+
Xor(a = false, b = sel[0], out = Xorb1);
35+
Xor(a = true, b = sel[1], out = Xorb2);
36+
And(a = Xorb1, b = Xorb2, out = And2);
37+
And16to1(a = And2, b = true, out = canb);
38+
And16(a = b, b = canb, out = outb);
39+
//c
40+
Xor(a = true, b = sel[0], out = Xorc1);
41+
Xor(a = false, b = sel[1], out = Xorc2);
42+
And(a = Xorc1, b = Xorc2, out = And3);
43+
And16to1(a = And3, b = true, out = canc);
44+
And16(a = c, b = canc, out = outc);
45+
//d
46+
Xor(a = false, b = sel[0], out = Xord1);
47+
Xor(a = false, b = sel[1], out = Xord2);
48+
And(a = Xord1, b = Xord2, out = And4);
49+
And16to1(a = And4, b = true, out = cand);
50+
And16(a = d, b = cand, out = outd);
51+
//Or
52+
Or16(a = outa, b = outb, out = Orab);
53+
Or16(a = Orab, b = outc, out = Orabc);
54+
Or16(a = Orabc, b = outd, out = out);
55+
}

0 commit comments

Comments
 (0)