forked from ccccourse/co108a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Add16.hdl
33 lines (30 loc) · 1.17 KB
/
Add16.hdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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/02/Adder16.hdl
/**
* Adds two 16-bit values.
* The most significant carry bit is ignored.
*/
CHIP Add16 {
IN a[16], b[16];
OUT out[16];
PARTS:
// Put you code here:
HalfAdder(a=a[0],b=b[0],sum=out[0],carry=c);
FullAdder(a=a[1],b=b[1],c=c,sum=out[1],carry=d);
FullAdder(a=a[2],b=b[2],c=d,sum=out[2],carry=e);
FullAdder(a=a[3],b=b[3],c=e,sum=out[3],carry=f);
FullAdder(a=a[4],b=b[4],c=f,sum=out[4],carry=g);
FullAdder(a=a[5],b=b[5],c=g,sum=out[5],carry=h);
FullAdder(a=a[6],b=b[6],c=h,sum=out[6],carry=i);
FullAdder(a=a[7],b=b[7],c=i,sum=out[7],carry=j);
FullAdder(a=a[8],b=b[8],c=j,sum=out[8],carry=k);
FullAdder(a=a[9],b=b[9],c=k,sum=out[9],carry=l);
FullAdder(a=a[10],b=b[10],c=l,sum=out[10],carry=m);
FullAdder(a=a[11],b=b[11],c=m,sum=out[11],carry=n);
FullAdder(a=a[12],b=b[12],c=n,sum=out[12],carry=o);
FullAdder(a=a[13],b=b[13],c=o,sum=out[13],carry=p);
FullAdder(a=a[14],b=b[14],c=p,sum=out[14],carry=q);
FullAdder(a=a[15],b=b[15],c=q,sum=out[15],carry=drop);
}