Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20221205 #19

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 01/And.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ CHIP And {

PARTS:
// Put your code here:
Nand(a=a,b=b,out = anandb );
Nand(a=anandb,b=anandb,out = out);
}
5 changes: 5 additions & 0 deletions 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 |
17 changes: 17 additions & 0 deletions 01/And16.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,21 @@ CHIP And16 {

PARTS:
// Put your code here:
//網路上找查的
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 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 | 0000000000000000 |
| 1010101010101010 | 0101010101010101 | 0000000000000000 |
| 0011110011000011 | 0000111111110000 | 0000000000000000 |
| 0001001000110100 | 1001100001110110 | 0000000000000000 |
4 changes: 4 additions & 0 deletions 01/DMux.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ CHIP DMux {

PARTS:
// Put your code here:
//網路上找查
Not(in=sel, out=nsel);
And(a=nsel, b=in, out=a);
And(a=sel, b=in, out=b);
}
5 changes: 5 additions & 0 deletions 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 | 0 | 0 |
| 1 | 1 | 0 | 0 |
4 changes: 4 additions & 0 deletions 01/DMux4Way.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ CHIP DMux4Way {

PARTS:
// Put your code here:
//網路上找查
DMux(in=in, sel=sel[1], a=c1, b=c2);
DMux(in=c1, sel=sel[0], a=a, b=b);
DMux(in=c2, sel=sel[0], a=c, b=d);
}
9 changes: 9 additions & 0 deletions 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 | 0 | 0 | 0 | 0 |
| 1 | 01 | 0 | 0 | 0 | 0 |
| 1 | 10 | 0 | 0 | 0 | 0 |
| 1 | 11 | 0 | 0 | 0 | 0 |
4 changes: 4 additions & 0 deletions 01/DMux8Way.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ CHIP DMux8Way {

PARTS:
// Put your code here:
//網路上找查
DMux(in=in, sel=sel[2], a=c1, b=c2);
DMux4Way(in=c1, sel[0]=sel[0], sel[1]=sel[1], a=a, b=b, c=c, d=d);
DMux4Way(in=c2, sel[0]=sel[0], sel[1]=sel[1], a=e, b=f, c=g, d=h);
}
17 changes: 17 additions & 0 deletions 01/DMux8Way.out
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 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 101 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
5 changes: 5 additions & 0 deletions 01/Mux.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ CHIP Mux {

PARTS:
// Put your code here:
//網路上找查
Not(in=sel, out=nsel);
And(a=sel, b=b, out=c1);
And(a=nsel, b=a, out=c2);
Or(a=c1, b=c2, out=out);
}
9 changes: 9 additions & 0 deletions 01/Mux.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
| a | b | sel | out |
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
17 changes: 17 additions & 0 deletions 01/Mux16.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@ CHIP Mux16 {

PARTS:
// Put your code here:
//網路上找查
Mux(a=a[0], b=b[0], sel=sel, out=out[0]);
Mux(a=a[1], b=b[1], sel=sel, out=out[1]);
Mux(a=a[2], b=b[2], sel=sel, out=out[2]);
Mux(a=a[3], b=b[3], sel=sel, out=out[3]);
Mux(a=a[4], b=b[4], sel=sel, out=out[4]);
Mux(a=a[5], b=b[5], sel=sel, out=out[5]);
Mux(a=a[6], b=b[6], sel=sel, out=out[6]);
Mux(a=a[7], b=b[7], sel=sel, out=out[7]);
Mux(a=a[8], b=b[8], sel=sel, out=out[8]);
Mux(a=a[9], b=b[9], sel=sel, out=out[9]);
Mux(a=a[10], b=b[10], sel=sel, out=out[10]);
Mux(a=a[11], b=b[11], sel=sel, out=out[11]);
Mux(a=a[12], b=b[12], sel=sel, out=out[12]);
Mux(a=a[13], b=b[13], sel=sel, out=out[13]);
Mux(a=a[14], b=b[14], sel=sel, out=out[14]);
Mux(a=a[15], b=b[15], sel=sel, out=out[15]);
}
9 changes: 9 additions & 0 deletions 01/Mux16.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
| a | b | sel | out |
| 0000000000000000 | 0000000000000000 | 0 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 1 | 0000000000000000 |
| 0000000000000000 | 0001001000110100 | 0 | 0000000000000000 |
| 0000000000000000 | 0001001000110100 | 1 | 0000000000000000 |
| 1001100001110110 | 0000000000000000 | 0 | 0000000000000000 |
| 1001100001110110 | 0000000000000000 | 1 | 0000000000000000 |
| 1010101010101010 | 0101010101010101 | 0 | 0000000000000000 |
| 1010101010101010 | 0101010101010101 | 1 | 0000000000000000 |
4 changes: 4 additions & 0 deletions 01/Mux4Way16.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ CHIP Mux4Way16 {

PARTS:
// Put your code here:
//網路上找查
Mux16(a=a, b=b, sel=sel[0], out=c1);
Mux16(a=c, b=d, sel=sel[0], out=c2);
Mux16(a=c1, b=c2, sel=sel[1], out=out);
}
9 changes: 9 additions & 0 deletions 01/Mux4Way16.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
| a | b | c | d | sel | out |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 00 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 01 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 10 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 11 | 0000000000000000 |
| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 00 | 0000000000000000 |
| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 01 | 0000000000000000 |
| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 10 | 0000000000000000 |
| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 11 | 0000000000000000 |
4 changes: 4 additions & 0 deletions 01/Mux8Way16.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ CHIP Mux8Way16 {

PARTS:
// Put your code here:
//網路上找查
Mux4Way16(a=a, b=b, c=c, d=d, sel[0]=sel[0], sel[1]=sel[1], out=c1);
Mux4Way16(a=e, b=f, c=g, d=h, sel[0]=sel[0], sel[1]=sel[1], out=c2);
Mux16(a=c1, b=c2, sel=sel[2], out=out);
}
17 changes: 17 additions & 0 deletions 01/Mux8Way16.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
| a | b | c | d | e | f | g | h | sel | out |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 000 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 001 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 010 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 011 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 100 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 101 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 110 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 111 | 0000000000000000 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 000 | 0000000000000000 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 001 | 0000000000000000 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 010 | 0000000000000000 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 011 | 0000000000000000 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 100 | 0000000000000000 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 101 | 0000000000000000 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 110 | 0000000000000000 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 111 | 0000000000000000 |
3 changes: 0 additions & 3 deletions 01/Not.out
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
| in | out |
| 0 | 1 |
| 1 | 0 |
17 changes: 17 additions & 0 deletions 01/Not16.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,21 @@ CHIP Not16 {

PARTS:
// Put your code here:
//網路上找查
Nand(a=in[0], b=in[0], out=out[0]);
Nand(a=in[1], b=in[1], out=out[1]);
Nand(a=in[2], b=in[2], out=out[2]);
Nand(a=in[3], b=in[3], out=out[3]);
Nand(a=in[4], b=in[4], out=out[4]);
Nand(a=in[5], b=in[5], out=out[5]);
Nand(a=in[6], b=in[6], out=out[6]);
Nand(a=in[7], b=in[7], out=out[7]);
Nand(a=in[8], b=in[8], out=out[8]);
Nand(a=in[9], b=in[9], out=out[9]);
Nand(a=in[10], b=in[10], out=out[10]);
Nand(a=in[11], b=in[11], out=out[11]);
Nand(a=in[12], b=in[12], out=out[12]);
Nand(a=in[13], b=in[13], out=out[13]);
Nand(a=in[14], b=in[14], out=out[14]);
Nand(a=in[15], b=in[15], out=out[15]);
}
6 changes: 6 additions & 0 deletions 01/Not16.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| in | out |
| 0000000000000000 | 0000000000000000 |
| 1111111111111111 | 0000000000000000 |
| 1010101010101010 | 0000000000000000 |
| 0011110011000011 | 0000000000000000 |
| 0001001000110100 | 0000000000000000 |
3 changes: 3 additions & 0 deletions 01/Or.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ CHIP Or {

PARTS:
// Put your code here:
Nand(a=a, b=a, out=aa);
Nand(a=b, b=b, out=bb);
Nand(a=aa, b=bb, out=out);
}
5 changes: 5 additions & 0 deletions 01/Or.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 | 0 |
17 changes: 17 additions & 0 deletions 01/Or16.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,21 @@ CHIP Or16 {

PARTS:
// Put your code here:
//網路上找查
Or(a=a[0],b=b[0],out=out[0]);
Or(a=a[1],b=b[1],out=out[1]);
Or(a=a[2],b=b[2],out=out[2]);
Or(a=a[3],b=b[3],out=out[3]);
Or(a=a[4],b=b[4],out=out[4]);
Or(a=a[5],b=b[5],out=out[5]);
Or(a=a[6],b=b[6],out=out[6]);
Or(a=a[7],b=b[7],out=out[7]);
Or(a=a[8],b=b[8],out=out[8]);
Or(a=a[9],b=b[9],out=out[9]);
Or(a=a[10],b=b[10],out=out[10]);
Or(a=a[11],b=b[11],out=out[11]);
Or(a=a[12],b=b[12],out=out[12]);
Or(a=a[13],b=b[13],out=out[13]);
Or(a=a[14],b=b[14],out=out[14]);
Or(a=a[15],b=b[15],out=out[15]);
}
7 changes: 7 additions & 0 deletions 01/Or16.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 | 0000000000000000 |
| 1010101010101010 | 0101010101010101 | 0000000000000000 |
| 0011110011000011 | 0000111111110000 | 0000000000000000 |
| 0001001000110100 | 1001100001110110 | 0000000000000000 |
8 changes: 8 additions & 0 deletions 01/Or8Way.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ CHIP Or8Way {

PARTS:
// Put your code here:
//網路上找查
Or(a=in[0], b=in[1], out=c1);
Or(a=in[2], b=in[3], out=c2);
Or(a=in[4], b=in[5], out=c3);
Or(a=in[6], b=in[7], out=c4);
Or(a=c1, b=c2, out=c5);
Or(a=c3, b=c4, out=c6);
Or(a=c5, b=c6, out=out);
}
6 changes: 6 additions & 0 deletions 01/Or8Way.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| in | out |
| 00000000 | 0 |
| 11111111 | 0 |
| 00010000 | 0 |
| 00000001 | 0 |
| 00100110 | 0 |
4 changes: 4 additions & 0 deletions 01/Xor.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ CHIP Xor {

PARTS:
// Put your code here:
//網路上找查
Or(a=a, b=b, out=c1);
Nand(a=a, b=b, out=c2);
And(a=c1, b=c2, out=out);
}
5 changes: 5 additions & 0 deletions 01/Xor.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 | 0 |
34 changes: 34 additions & 0 deletions 02/ALU.hdl
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,38 @@ CHIP ALU {

PARTS:
// Put you code here:
// if (zx == 1) set x = 0 // 16-bit constant
Mux16(a = x, b[0..15] = false, sel = zx, out = ozx);

// if (nx == 1) set x = !x // bitwise not
Not16(in = ozx, out = nnx);
Mux16(a = ozx, b = nnx, sel = nx, out = exx);

// if (zy == 1) set y = 0 // 16-bit constant
Mux16(a = y, b[0..15] = false, sel = zy, out = ozy);

// if (ny == 1) set y = !y // bitwise not
Not16(in = ozy, out = nny);
Mux16(a = ozy, b = nny, sel = ny, out = exy);

// if (f == 1) set out = x + y // integer 2's complement addition
// if (f == 0) set out = x & y // bitwise and
Add16(a = exx, b = exy, out = xplusy);
And16(a = exx, b = exy, out = xandy);
Mux16(a = xandy, b = xplusy, sel = f, out = fxy);

// if (no == 1) set out = !out // bitwise not
Not16(in = fxy, out = nfxy);
Mux16(a = fxy, b = nfxy, sel = no, out[0..7] = ret0, out[8..14] = ret1, out[15] = retsign, out = out);

// if (out == 0) set zr = 1
Or8Way(in[0..7] = ret0, out = ret0is0);
Or8Way(in[0..6] = ret1, in[7] = retsign, out = ret1is0);

Or(a = ret0is0, b = ret1is0, out = yzr);
Not(in = yzr, out = zr);

// if (out < 0) set ng = 1
//And(a = retsign, b = true, out = ng);
Mux(a = false , b = true , sel = retsign , out = ng);
}
Loading