Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented the initial project 2 ALU chips

  • Loading branch information...
commit 2d8e9bc9d4eeae48c951d9b4b610876d88fd75a0 1 parent faf69b3
Ben Griffiths authored
22 project2/Add16.hdl
View
@@ -1,8 +1,3 @@
-// This file is part of the materials accompanying the book
-// "The Elements of Computing Systems" by Nisan and Schocken,
-// MIT Press. Book site: www.idc.ac.il/tecs
-// File name: projects/02/Adder16.hdl
-
/*
* Adds two 16-bit values.
* The most-significant carry bit is ignored.
@@ -13,5 +8,20 @@ CHIP Add16 {
OUT out[16];
PARTS:
- // Put your code here.
+ HalfAdder(a=a[0], b=b[0], sum=out[0], carry=oCarry1);
+ FullAdder(a=a[1], b=b[1], c=oCarry1, sum=out[1], carry=oCarry2);
+ FullAdder(a=a[2], b=b[2], c=oCarry2, sum=out[2], carry=oCarry3);
+ FullAdder(a=a[3], b=b[3], c=oCarry3, sum=out[3], carry=oCarry4);
+ FullAdder(a=a[4], b=b[4], c=oCarry4, sum=out[4], carry=oCarry5);
+ FullAdder(a=a[5], b=b[5], c=oCarry5, sum=out[5], carry=oCarry6);
+ FullAdder(a=a[6], b=b[6], c=oCarry6, sum=out[6], carry=oCarry7);
+ FullAdder(a=a[7], b=b[7], c=oCarry7, sum=out[7], carry=oCarry8);
+ FullAdder(a=a[8], b=b[8], c=oCarry8, sum=out[8], carry=oCarry9);
+ FullAdder(a=a[9], b=b[9], c=oCarry9, sum=out[9], carry=oCarry10);
+ FullAdder(a=a[10], b=b[10], c=oCarry10, sum=out[10], carry=oCarry11);
+ FullAdder(a=a[11], b=b[11], c=oCarry11, sum=out[11], carry=oCarry12);
+ FullAdder(a=a[12], b=b[12], c=oCarry12, sum=out[12], carry=oCarry13);
+ FullAdder(a=a[13], b=b[13], c=oCarry13, sum=out[13], carry=oCarry14);
+ FullAdder(a=a[14], b=b[14], c=oCarry14, sum=out[14], carry=oCarry15);
+ FullAdder(a=a[15], b=b[15], c=oCarry15, sum=out[15], carry=toNull);
}
7 project2/Add16.out
View
@@ -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 |
9 project2/FullAdder.hdl
View
@@ -1,8 +1,3 @@
-// This file is part of the materials accompanying the book
-// "The Elements of Computing Systems" by Nisan and Schocken,
-// MIT Press. Book site: www.idc.ac.il/tecs
-// File name: projects/02/FullAdder.hdl
-
/**
* Computes the sum of three bits.
*/
@@ -13,5 +8,7 @@ CHIP FullAdder {
carry; // Left bit of a + b + c
PARTS:
- // Put your code here.
+ HalfAdder(a=a, b=b, sum=abSum, carry=abCarry);
+ HalfAdder(a=abSum, b=c, sum=sum, carry=abSumCCarry);
+ Or(a=abCarry, b=abSumCCarry, out=carry);
}
9 project2/FullAdder.out
View
@@ -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 |
8 project2/HalfAdder.hdl
View
@@ -1,8 +1,3 @@
-// This file is part of the materials accompanying the book
-// "The Elements of Computing Systems" by Nisan and Schocken,
-// MIT Press. Book site: www.idc.ac.il/tecs
-// File name: projects/02/HalfAdder.hdl
-
/**
* Computes the sum of two bits.
*/
@@ -13,5 +8,6 @@ CHIP HalfAdder {
carry; // Left bit of a + b
PARTS:
- // Put your code here.
+ And(a=a, b=b, out=carry);
+ Xor(a=a, b=b, out=sum);
}
5 project2/HalfAdder.out
View
@@ -0,0 +1,5 @@
+| a | b | sum | carry |
+| 0 | 0 | 0 | 0 |
+| 0 | 1 | 1 | 0 |
+| 1 | 0 | 1 | 0 |
+| 1 | 1 | 0 | 1 |
7 project2/Inc16.hdl
View
@@ -1,8 +1,3 @@
-// This file is part of the materials accompanying the book
-// "The Elements of Computing Systems" by Nisan and Schocken,
-// MIT Press. Book site: www.idc.ac.il/tecs
-// File name: projects/02/Inc16.hdl
-
/**
* 16-bit incrementer: out = in + 1 (arithmetic addition)
*/
@@ -12,5 +7,5 @@ CHIP Inc16 {
OUT out[16];
PARTS:
- // Put your code here.
+ Add16(a=in, b[0]=true, b[1..15]=false, out=out);
}
5 project2/Inc16.out
View
@@ -0,0 +1,5 @@
+| in | out |
+| 0000000000000000 | 0000000000000001 |
+| 1111111111111111 | 0000000000000000 |
+| 0000000000000101 | 0000000000000110 |
+| 1111111111111011 | 1111111111111100 |
Please sign in to comment.
Something went wrong with that request. Please try again.