/* Full adder.
   Syntax: Full_Adder a b c-in | c-out s;
   Effect: Adds binary numbers a + b with carry.
*/
Define Full_Adder a b CarryIn | CarryOut Sum;
  Xor aa a b x;
  Xor ab x CarryIn Sum;
  And bb a b y;
  And cb CarryIn x z;
  Or bc-cc y z CarryOut;
Endef;


/* ------------------------- 
   MAIN
   ------------------------- */

/* Put up first input number */
Switch aa x3 ZERO;
Switch ab x2 ZERO;
Switch ac x1 ZERO;
Switch ad x0 ZERO;

/* Put up second input number */
Switch af y3 ZERO;
Switch ag y2 ZERO;
Switch ah y1 ZERO;
Switch ai y0 ZERO;

Full_Adder cb x3 y3 c3   | c4 s3;
Full_Adder cd x2 y2 c2   | c3 s2;
Full_Adder cf x1 y1 c1   | c2 s1;
Full_Adder ch x0 y0 ZERO | c1 s0;

/* Probe the outputs */
Probe "Carry" ea c4;

Probe "s3" ec s3;
Probe "s2" ed s2;
Probe "s1" ee s1;
Probe "s0" ef s0;
