/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. * Full adder. Computes sum, the least significant bit of
  7. * a + b + c, and carry, the most significant bit of a + b + c.
  8. *
  9. * The LSB of a + b +c = LSB(a + b) + c
  10. * The MSB of a + b + c = MSB(a + b), MSB can never be more than 1
  11. * given that max sum is 1 + 1 + 1 = 11
  12. */
  13. CHIP FullAdder {
  14. IN a, b, c;
  15. OUT sum, // LSB of a + b + c
  16. carry; // MSB of a + b + c
  17. PARTS:
  18. HalfAdder(a=a, b=b, sum=absum, carry=abcarry);
  19. HalfAdder(a=absum, b=c, sum=sum, carry=abccarry);
  20. Xor(a=abcarry, b=abccarry, out=carry);
  21. }