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
|
// 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);
}
|