Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WuShaoa committed Dec 13, 2020
0 parents commit e1e04ff
Show file tree
Hide file tree
Showing 488 changed files with 254,066 additions and 0 deletions.
Binary file added SIGCSE2009.pdf
Binary file not shown.
Binary file added VM.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions projects/00/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The only purpose of this file is to practice submitting files
in the Nand to Tetris course websites in Coursera.

There is no need to modify the contents of this file.
All you have to do is submit it as is, following the
Project 0 guidelines in the website.
5 changes: 5 additions & 0 deletions projects/01/And.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| a | b | out |
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
19 changes: 19 additions & 0 deletions projects/01/And.hdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And.hdl

/**
* And gate:
* out = 1 if (a == 1 and b == 1)
* 0 otherwise
*/

CHIP And {
IN a, b;
OUT out;

PARTS:
Nand(a=a, b=b, out=x);
Not(in=x, out=out);
}
5 changes: 5 additions & 0 deletions projects/01/And.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| a | b | out |
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
29 changes: 29 additions & 0 deletions projects/01/And.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And.tst

load And.hdl,
output-file And.out,
compare-to And.cmp,
output-list a%B3.1.3 b%B3.1.3 out%B3.1.3;

set a 0,
set b 0,
eval,
output;

set a 0,
set b 1,
eval,
output;

set a 1,
set b 0,
eval,
output;

set a 1,
set b 1,
eval,
output;
7 changes: 7 additions & 0 deletions projects/01/And16.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| a | b | out |
| 0000000000000000 | 0000000000000000 | 0000000000000000 |
| 0000000000000000 | 1111111111111111 | 0000000000000000 |
| 1111111111111111 | 1111111111111111 | 1111111111111111 |
| 1010101010101010 | 0101010101010101 | 0000000000000000 |
| 0011110011000011 | 0000111111110000 | 0000110011000000 |
| 0001001000110100 | 1001100001110110 | 0001000000110100 |
33 changes: 33 additions & 0 deletions projects/01/And16.hdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And16.hdl

/**
* 16-bit bitwise And:
* for i = 0..15: out[i] = (a[i] and b[i])
*/

CHIP And16 {
IN a[16], b[16];
OUT out[16];

PARTS:
And(a=a[0], b=b[0], out=out[0]);
And(a=a[1], b=b[1], out=out[1]);
And(a=a[2], b=b[2], out=out[2]);
And(a=a[3], b=b[3], out=out[3]);
And(a=a[4], b=b[4], out=out[4]);
And(a=a[5], b=b[5], out=out[5]);
And(a=a[6], b=b[6], out=out[6]);
And(a=a[7], b=b[7], out=out[7]);
And(a=a[8], b=b[8], out=out[8]);
And(a=a[9], b=b[9], out=out[9]);
And(a=a[10], b=b[10], out=out[10]);
And(a=a[11], b=b[11], out=out[11]);
And(a=a[12], b=b[12], out=out[12]);
And(a=a[13], b=b[13], out=out[13]);
And(a=a[14], b=b[14], out=out[14]);
And(a=a[15], b=b[15], out=out[15]);

}
7 changes: 7 additions & 0 deletions projects/01/And16.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| a | b | out |
| 0000000000000000 | 0000000000000000 | 0000000000000000 |
| 0000000000000000 | 1111111111111111 | 0000000000000000 |
| 1111111111111111 | 1111111111111111 | 1111111111111111 |
| 1010101010101010 | 0101010101010101 | 0000000000000000 |
| 0011110011000011 | 0000111111110000 | 0000110011000000 |
| 0001001000110100 | 1001100001110110 | 0001000000110100 |
39 changes: 39 additions & 0 deletions projects/01/And16.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And16.tst

load And16.hdl,
output-file And16.out,
compare-to And16.cmp,
output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;

set a %B0000000000000000,
set b %B0000000000000000,
eval,
output;

set a %B0000000000000000,
set b %B1111111111111111,
eval,
output;

set a %B1111111111111111,
set b %B1111111111111111,
eval,
output;

set a %B1010101010101010,
set b %B0101010101010101,
eval,
output;

set a %B0011110011000011,
set b %B0000111111110000,
eval,
output;

set a %B0001001000110100,
set b %B1001100001110110,
eval,
output;
5 changes: 5 additions & 0 deletions projects/01/DMux.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| in | sel | a | b |
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
20 changes: 20 additions & 0 deletions projects/01/DMux.hdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux.hdl

/**
* Demultiplexor:
* {a, b} = {in, 0} if sel == 0
* {0, in} if sel == 1
*/

CHIP DMux {
IN in, sel;
OUT a, b;

PARTS:
Not(in=sel, out=nsel);
And(a=in, b=nsel, out=a);
And(a=in, b=sel, out=b);
}
5 changes: 5 additions & 0 deletions projects/01/DMux.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| in | sel | a | b |
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
27 changes: 27 additions & 0 deletions projects/01/DMux.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux.tst

load DMux.hdl,
output-file DMux.out,
compare-to DMux.cmp,
output-list in%B3.1.3 sel%B3.1.3 a%B3.1.3 b%B3.1.3;

set in 0,
set sel 0,
eval,
output;

set sel 1,
eval,
output;

set in 1,
set sel 0,
eval,
output;

set sel 1,
eval,
output;
9 changes: 9 additions & 0 deletions projects/01/DMux4Way.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
| in | sel | a | b | c | d |
| 0 | 00 | 0 | 0 | 0 | 0 |
| 0 | 01 | 0 | 0 | 0 | 0 |
| 0 | 10 | 0 | 0 | 0 | 0 |
| 0 | 11 | 0 | 0 | 0 | 0 |
| 1 | 00 | 1 | 0 | 0 | 0 |
| 1 | 01 | 0 | 1 | 0 | 0 |
| 1 | 10 | 0 | 0 | 1 | 0 |
| 1 | 11 | 0 | 0 | 0 | 1 |
33 changes: 33 additions & 0 deletions projects/01/DMux4Way.hdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux4Way.hdl

/**
* 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
*/

CHIP DMux4Way {
IN in, sel[2];
OUT a, b, c, d;

PARTS:
Not(in=sel[0], out=ns0);
Not(in=sel[1], out=ns1);

And(a=ns0, b=ns1, out=xa);
And(a=in, b=xa, out=a);

And(a=sel[0], b=ns1, out=xb);
And(a=in, b=xb, out=b);

And(a=ns0, b=sel[1], out=xc);
And(a=in, b=xc, out=c);

And(a=sel[0], b=sel[1], out=xd);
And(a=in, b=xd, out=d);
}
9 changes: 9 additions & 0 deletions projects/01/DMux4Way.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
| in | sel | a | b | c | d |
| 0 | 00 | 0 | 0 | 0 | 0 |
| 0 | 01 | 0 | 0 | 0 | 0 |
| 0 | 10 | 0 | 0 | 0 | 0 |
| 0 | 11 | 0 | 0 | 0 | 0 |
| 1 | 00 | 1 | 0 | 0 | 0 |
| 1 | 01 | 0 | 1 | 0 | 0 |
| 1 | 10 | 0 | 0 | 1 | 0 |
| 1 | 11 | 0 | 0 | 0 | 1 |
43 changes: 43 additions & 0 deletions projects/01/DMux4Way.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux4Way.tst

load DMux4Way.hdl,
output-file DMux4Way.out,
compare-to DMux4Way.cmp,
output-list in%B2.1.2 sel%B2.2.2 a%B2.1.2 b%B2.1.2 c%B2.1.2 d%B2.1.2;

set in 0,
set sel %B00,
eval,
output;

set sel %B01,
eval,
output;

set sel %B10,
eval,
output;

set sel %B11,
eval,
output;

set in 1,
set sel %B00,
eval,
output;

set sel %B01,
eval,
output;

set sel %B10,
eval,
output;

set sel %B11,
eval,
output;
17 changes: 17 additions & 0 deletions projects/01/DMux8Way.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
| in | sel | a | b | c | d | e | f | g | h |
| 0 | 000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 101 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 000 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 001 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 010 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 1 | 011 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 1 | 100 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 1 | 101 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 1 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 1 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
54 changes: 54 additions & 0 deletions projects/01/DMux8Way.hdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux8Way.hdl

/**
* 8-way demultiplexor:
* {a, b, c, d, e, f, g, h} = {in, 0, 0, 0, 0, 0, 0, 0} if sel == 000
* {0, in, 0, 0, 0, 0, 0, 0} if sel == 001
* etc.
* {0, 0, 0, 0, 0, 0, 0, in} if sel == 111
*/

CHIP DMux8Way {
IN in, sel[3];
OUT a, b, c, d, e, f, g, h;

PARTS:
Not(in=sel[0], out=ns0);
Not(in=sel[1], out=ns1);
Not(in=sel[2], out=ns2);

And(a=ns0, b=ns1, out=o0);
And(a=o0, b=ns2, out=x0);
And(a=in, b=x0, out=a);

And(a=sel[0], b=ns1, out=o1);
And(a=o1, b=ns2, out=x1);
And(a=in, b=x1, out=b);

And(a=ns0, b=sel[1], out=o2);
And(a=o2, b=ns2, out=x2);
And(a=in, b=x2, out=c);

And(a=sel[0], b=sel[1], out=o3);
And(a=o3, b=ns2, out=x3);
And(a=in, b=x3, out=d);

And(a=ns0, b=ns1, out=o4);
And(a=o4, b=sel[2], out=x4);
And(a=in, b=x4, out=e);

And(a=sel[0], b=ns1, out=o5);
And(a=o5, b=sel[2], out=x5);
And(a=in, b=x5, out=f);

And(a=ns0, b=sel[1], out=o6);
And(a=o6, b=sel[2], out=x6);
And(a=in, b=x6, out=g);

And(a=sel[0], b=sel[1], out=o7);
And(a=o7, b=sel[2], out=x7);
And(a=in, b=x7, out=h);
}
Loading

0 comments on commit e1e04ff

Please sign in to comment.