aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--projects/02/ALU.hdl18
-rw-r--r--projects/02/ALU.out37
-rw-r--r--projects/02/Add16.hdl18
-rw-r--r--projects/02/Add16.out7
-rw-r--r--projects/02/FullAdder.hdl5
-rw-r--r--projects/02/FullAdder.out9
-rw-r--r--projects/02/HalfAdder.hdl2
-rw-r--r--projects/02/HalfAdder.out5
-rw-r--r--projects/02/Inc16.hdl3
-rw-r--r--projects/02/Inc16.out5
-rw-r--r--projects/02/Test.hdl8
11 files changed, 113 insertions, 4 deletions
diff --git a/projects/02/ALU.hdl b/projects/02/ALU.hdl
index 9a753e3..47697a0 100644
--- a/projects/02/ALU.hdl
+++ b/projects/02/ALU.hdl
@@ -43,4 +43,20 @@ CHIP ALU {
PARTS:
// Put you code here:
-} \ No newline at end of file
+ Mux16 (a=x, b[0..15]=false, sel=zx, out=x1);
+ Not16 (in=x1, out=notx1);
+ Mux16 (a=x1, b=notx1, sel=nx, out=x2);
+ Mux16 (a=y, b[0..15]=false, sel=zy, out=y1);
+ Not16 (in=y1, out=noty1);
+ Mux16 (a=y1, b=noty1, sel=ny, out=y2);
+ Add16 (a=x2, b=y2, out=x2py2);
+ And16 (a=x2, b=y2, out=x2ay2);
+ Mux16 (a=x2ay2, b=x2py2, sel=f, out=xy);
+ Not16 (in=xy, out=notxy);
+ Mux16 (a=xy, b=notxy, sel=no, out=out, out[0..7]=out1, out[8..15]=out2, out[15]=msbout);
+ Or8Way (in=out1, out=z1);
+ Or8Way (in=out1, out=z2); //some potential pitfall w.r.t. subbusing see https://www.coursera.org/learn/build-a-computer/discussions/weeks/2/threads/9VYr3LzkEeeK2BJ0oEsgKA
+ Or (a=z1, b=z2, out=z);
+ Not (in=z, out=zr);
+ And (a=msbout, b=true, out=ng);
+}
diff --git a/projects/02/ALU.out b/projects/02/ALU.out
new file mode 100644
index 0000000..2424a73
--- /dev/null
+++ b/projects/02/ALU.out
@@ -0,0 +1,37 @@
+| x | y |zx |nx |zy |ny | f |no | out |zr |ng |
+| 0000000000000000 | 1111111111111111 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 | 1 | 0 |
+| 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 |
+| 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 |
+| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 0 | 0000000000000000 | 1 | 0 |
+| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 0 | 1111111111111111 | 0 | 1 |
+| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 1 | 1111111111111111 | 0 | 1 |
+| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 1 | 0000000000000000 | 1 | 0 |
+| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 1 | 0000000000000000 | 1 | 0 |
+| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 | 0 | 0 |
+| 0000000000000000 | 1111111111111111 | 0 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 |
+| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 1 | 1 | 1 | 0000000000000000 | 1 | 0 |
+| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 0 | 1111111111111111 | 0 | 1 |
+| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 0 | 1111111111111110 | 0 | 1 |
+| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 |
+| 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 | 0 | 0 |
+| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 1 | 1 | 1 | 1111111111111111 | 0 | 1 |
+| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 0 | 0 | 0000000000000000 | 1 | 0 |
+| 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 1 | 0 | 1 | 1111111111111111 | 0 | 1 |
+| 0000000000010001 | 0000000000000011 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 | 1 | 0 |
+| 0000000000010001 | 0000000000000011 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 |
+| 0000000000010001 | 0000000000000011 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 |
+| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 0 | 0 | 0000000000010001 | 0 | 0 |
+| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 0 | 0 | 0000000000000011 | 0 | 0 |
+| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 0 | 1 | 1111111111101110 | 0 | 1 |
+| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 0 | 1 | 1111111111111100 | 0 | 1 |
+| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 1 | 1 | 1111111111101111 | 0 | 1 |
+| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 1 | 1 | 1111111111111101 | 0 | 1 |
+| 0000000000010001 | 0000000000000011 | 0 | 1 | 1 | 1 | 1 | 1 | 0000000000010010 | 0 | 0 |
+| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 1 | 1 | 1 | 0000000000000100 | 0 | 0 |
+| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 1 | 0 | 0000000000010000 | 0 | 0 |
+| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 1 | 0 | 0000000000000010 | 0 | 0 |
+| 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 0 | 1 | 0 | 0000000000010100 | 0 | 0 |
+| 0000000000010001 | 0000000000000011 | 0 | 1 | 0 | 0 | 1 | 1 | 0000000000001110 | 0 | 0 |
+| 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 1 | 1 | 1 | 1111111111110010 | 0 | 1 |
+| 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 0 | 0 | 0 | 0000000000000001 | 0 | 0 |
+| 0000000000010001 | 0000000000000011 | 0 | 1 | 0 | 1 | 0 | 1 | 0000000000010011 | 0 | 0 |
diff --git a/projects/02/Add16.hdl b/projects/02/Add16.hdl
index aa7604d..ea3cb80 100644
--- a/projects/02/Add16.hdl
+++ b/projects/02/Add16.hdl
@@ -14,4 +14,20 @@ CHIP Add16 {
PARTS:
// Put you code here:
-} \ No newline at end of file
+ HalfAdder (a=a[0], b=b[0], sum=out[0], carry=carry0);
+ FullAdder (a=a[1], b=b[1], c=carry0, sum=out[1], carry=carry1);
+ FullAdder (a=a[2], b=b[2], c=carry1, sum=out[2], carry=carry2);
+ FullAdder (a=a[3], b=b[3], c=carry2, sum=out[3], carry=carry3);
+ FullAdder (a=a[4], b=b[4], c=carry3, sum=out[4], carry=carry4);
+ FullAdder (a=a[5], b=b[5], c=carry4, sum=out[5], carry=carry5);
+ FullAdder (a=a[6], b=b[6], c=carry5, sum=out[6], carry=carry6);
+ FullAdder (a=a[7], b=b[7], c=carry6, sum=out[7], carry=carry7);
+ FullAdder (a=a[8], b=b[8], c=carry7, sum=out[8], carry=carry8);
+ FullAdder (a=a[9], b=b[9], c=carry8, sum=out[9], carry=carry9);
+ FullAdder (a=a[10], b=b[10], c=carry9, sum=out[10], carry=carry10);
+ FullAdder (a=a[11], b=b[11], c=carry10, sum=out[11], carry=carry11);
+ FullAdder (a=a[12], b=b[12], c=carry11, sum=out[12], carry=carry12);
+ FullAdder (a=a[13], b=b[13], c=carry12, sum=out[13], carry=carry13);
+ FullAdder (a=a[14], b=b[14], c=carry13, sum=out[14], carry=carry14);
+ FullAdder (a=a[15], b=b[15], c=carry14, sum=out[15], carry=carry15);
+}
diff --git a/projects/02/Add16.out b/projects/02/Add16.out
new file mode 100644
index 0000000..20f9c65
--- /dev/null
+++ b/projects/02/Add16.out
@@ -0,0 +1,7 @@
+| a | b | out |
+| 0000000000000000 | 0000000000000000 | 0000000000000000 |
+| 0000000000000000 | 1111111111111111 | 1111111111111111 |
+| 1111111111111111 | 1111111111111111 | 1111111111111110 |
+| 1010101010101010 | 0101010101010101 | 1111111111111111 |
+| 0011110011000011 | 0000111111110000 | 0100110010110011 |
+| 0001001000110100 | 1001100001110110 | 1010101010101010 |
diff --git a/projects/02/FullAdder.hdl b/projects/02/FullAdder.hdl
index 67559c3..451499f 100644
--- a/projects/02/FullAdder.hdl
+++ b/projects/02/FullAdder.hdl
@@ -14,4 +14,7 @@ CHIP FullAdder {
PARTS:
// Put you code here:
-} \ No newline at end of file
+ HalfAdder (a=a, b=b, sum=sum1, carry=carry1);
+ HalfAdder (a=sum1, b=c, sum=sum, carry=carry2);
+ Or (a=carry1, b=carry2, out=carry);
+}
diff --git a/projects/02/FullAdder.out b/projects/02/FullAdder.out
new file mode 100644
index 0000000..610181f
--- /dev/null
+++ b/projects/02/FullAdder.out
@@ -0,0 +1,9 @@
+| 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 |
diff --git a/projects/02/HalfAdder.hdl b/projects/02/HalfAdder.hdl
index 98b281f..0b40509 100644
--- a/projects/02/HalfAdder.hdl
+++ b/projects/02/HalfAdder.hdl
@@ -14,4 +14,6 @@ CHIP HalfAdder {
PARTS:
// Put you code here:
+ Xor (a=a, b=b, out=sum);
+ And (a=a, b=b, out=carry);
}
diff --git a/projects/02/HalfAdder.out b/projects/02/HalfAdder.out
new file mode 100644
index 0000000..612c8e3
--- /dev/null
+++ b/projects/02/HalfAdder.out
@@ -0,0 +1,5 @@
+| a | b | sum | carry |
+| 0 | 0 | 0 | 0 |
+| 0 | 1 | 1 | 0 |
+| 1 | 0 | 1 | 0 |
+| 1 | 1 | 0 | 1 |
diff --git a/projects/02/Inc16.hdl b/projects/02/Inc16.hdl
index fb6c0dd..8142695 100644
--- a/projects/02/Inc16.hdl
+++ b/projects/02/Inc16.hdl
@@ -14,4 +14,5 @@ CHIP Inc16 {
PARTS:
// Put you code here:
-} \ No newline at end of file
+ Add16 (a=in, b[0]=true, b[1..15]=false, out=out);
+}
diff --git a/projects/02/Inc16.out b/projects/02/Inc16.out
new file mode 100644
index 0000000..78de1fe
--- /dev/null
+++ b/projects/02/Inc16.out
@@ -0,0 +1,5 @@
+| in | out |
+| 0000000000000000 | 0000000000000001 |
+| 1111111111111111 | 0000000000000000 |
+| 0000000000000101 | 0000000000000110 |
+| 1111111111111011 | 1111111111111100 |
diff --git a/projects/02/Test.hdl b/projects/02/Test.hdl
new file mode 100644
index 0000000..4b12157
--- /dev/null
+++ b/projects/02/Test.hdl
@@ -0,0 +1,8 @@
+CHIP Test{
+ IN
+ x[16], y;
+ OUT
+ out[16];
+ PARTS:
+ Mux (a=x, b=true, out=out);
+}