PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/2/FullAdder.hdl

http://github.com/happy4crazy/elements_of_computing_systems
Unknown | 26 lines | 21 code | 5 blank | 0 comment | 0 complexity | 9e346ac1fb5bbaf306787ea583cd3688 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/FullAdder.hdl
 5
 6/**
 7 * Full adder. Computes sum, the least significant bit of 
 8 * a + b + c, and carry, the most significant bit of a + b + c.
 9 * 
10 * The LSB of a + b +c = LSB(a + b) + c
11 * The MSB of a + b + c = MSB(a + b), MSB can never be more than 1
12 * given that max sum is 1 + 1 + 1 = 11
13 */
14
15CHIP FullAdder {
16
17    IN  a, b, c;
18    OUT sum,     // LSB of a + b + c
19        carry;   // MSB of a + b + c
20
21    PARTS:
22    HalfAdder(a=a, b=b, sum=absum, carry=abcarry);
23    HalfAdder(a=absum, b=c, sum=sum, carry=abccarry);
24    Xor(a=abcarry, b=abccarry, out=carry);
25}
26