summaryrefslogtreecommitdiff
path: root/projects/02/Inc16.hdl
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-08-16 11:54:23 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-08-16 11:54:23 +0800
commit9542deeb483a00b6fabed7574720926ce97d7511 (patch)
tree0f2c1f72c03dd4693fd59df67544d2a4dddc5494 /projects/02/Inc16.hdl
parent9c0cb1d1c32724fc95ac9548e4f8d873d3adaccc (diff)
Projects, 01-06 completed
Diffstat (limited to 'projects/02/Inc16.hdl')
-rw-r--r--projects/02/Inc16.hdl32
1 files changed, 32 insertions, 0 deletions
diff --git a/projects/02/Inc16.hdl b/projects/02/Inc16.hdl
new file mode 100644
index 0000000..6b27473
--- /dev/null
+++ b/projects/02/Inc16.hdl
@@ -0,0 +1,32 @@
+// 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/02/Inc16.hdl
+
+/**
+ * 16-bit incrementer:
+ * out = in + 1 (arithmetic addition)
+ */
+
+CHIP Inc16 {
+ IN in[16];
+ OUT out[16];
+
+ PARTS:
+ Not(in=in[0], out=out[0]);
+ HalfAdder(a=in[1], b=in[0], sum=out[1], carry=c1);
+ HalfAdder(a=in[2], b=c1, sum=out[2], carry=c2);
+ HalfAdder(a=in[3], b=c2, sum=out[3], carry=c3);
+ HalfAdder(a=in[4], b=c3, sum=out[4], carry=c4);
+ HalfAdder(a=in[5], b=c4, sum=out[5], carry=c5);
+ HalfAdder(a=in[6], b=c5, sum=out[6], carry=c6);
+ HalfAdder(a=in[7], b=c6, sum=out[7], carry=c7);
+ HalfAdder(a=in[8], b=c7, sum=out[8], carry=c8);
+ HalfAdder(a=in[9], b=c8, sum=out[9], carry=c9);
+ HalfAdder(a=in[10], b=c9, sum=out[10], carry=c10);
+ HalfAdder(a=in[11], b=c10, sum=out[11], carry=c11);
+ HalfAdder(a=in[12], b=c11, sum=out[12], carry=c12);
+ HalfAdder(a=in[13], b=c12, sum=out[13], carry=c13);
+ HalfAdder(a=in[14], b=c13, sum=out[14], carry=c14);
+ HalfAdder(a=in[15], b=c14, sum=out[15], carry=c15);
+}