Posted by
cadet1620 on
Jan 08, 2015; 1:21pm
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Add16-tp4028597p4028607.html
You can use a FullAdder as a Half adder by setting the carry-in to zero:
FullAdder (a=a[0], b=b[0], c=false, sum=out[0], carry=c0);
...
Common real world adder parts have a pin for the bit 0 carry-in. This makes them chainable to make even wider adders. Given an Add16c chip:
IN a[16], b[16], c;
OUT out[16], carry;
PARTS:
FullAdder (a=a[0], b=b[0], c=c, sum=out[0], carry=c0);
...
FullAdder (a=a[15], b=b[15], c=c14, sum=out[0], carry=carry);
You could use it to make a 32-bit adder:
Add16c (a=a[0..15], b=b[0..15], c=false, out=out[0..15], carry=c15);
Add16c (a=a[16..31], b=b[16..31], c=c15, out=out[16..31]);
(Note that 32-bit parts are not supported by the simulator.)
Here's something to think about. What operation does this chip implement, and how does it work?
CHIP Something16 {
IN a[16], b[16];
OUT out[16];
PARTS:
Not16 (in=b, out=notB);
Add16c (a=a, b=notB, c=true, out=out);
}
--Mark