PageRenderTime 344ms CodeModel.GetById 161ms app.highlight 1ms RepoModel.GetById 140ms app.codeStats 0ms

/2/Add16.hdl

http://github.com/happy4crazy/elements_of_computing_systems
Unknown | 35 lines | 30 code | 5 blank | 0 comment | 0 complexity | 7703703ec670a9858069724c58f6e4ac MD5 | raw file
 1// This file is part of the materials accompanying the book 
 2// "The Elements of Computing Systems" by Nisan and Schocken, 
 3// MIT Press. Book site: www.idc.ac.il/tecs
 4// File name: projects/02/Add16.hdl
 5
 6/**
 7 * 16-bit integer adder.  out = a + b where a,b are 16-bit 
 8 * 2's complement representations of integers.  Overflow is 
 9 * neither detected nor handled.
10 */
11
12CHIP Add16 {
13
14    IN  a[16], b[16];
15    OUT out[16];
16
17    PARTS:
18    FullAdder(a=a[0], b=b[0], sum=out[0], carry=carry0);
19    FullAdder(a=a[1], b=b[1], c=carry0, sum=out[1], carry=carry1);
20    FullAdder(a=a[2], b=b[2], c=carry1, sum=out[2], carry=carry2);
21    FullAdder(a=a[3], b=b[3], c=carry2, sum=out[3], carry=carry3);
22    FullAdder(a=a[4], b=b[4], c=carry3, sum=out[4], carry=carry4);
23    FullAdder(a=a[5], b=b[5], c=carry4, sum=out[5], carry=carry5);
24    FullAdder(a=a[6], b=b[6], c=carry5, sum=out[6], carry=carry6);
25    FullAdder(a=a[7], b=b[7], c=carry6, sum=out[7], carry=carry7);
26    FullAdder(a=a[8], b=b[8], c=carry7, sum=out[8], carry=carry8);
27    FullAdder(a=a[9], b=b[9], c=carry8, sum=out[9], carry=carry9);
28    FullAdder(a=a[10], b=b[10], c=carry9, sum=out[10], carry=carry10);
29    FullAdder(a=a[11], b=b[11], c=carry10, sum=out[11], carry=carry11);
30    FullAdder(a=a[12], b=b[12], c=carry11, sum=out[12], carry=carry12);
31    FullAdder(a=a[13], b=b[13], c=carry12, sum=out[13], carry=carry13);
32    FullAdder(a=a[14], b=b[14], c=carry13, sum=out[14], carry=carry14);
33    FullAdder(a=a[15], b=b[15], c=carry14, sum=out[15], carry=carry15);
34}
35