/* Full adder.
   Syntax: Full_Adder c_in a b | c_out s;
   Effect: Adds binary numbers a + b with carry.
*/
Define Full_Adder CarryIn a b | 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;

Define FourBit_Adder   a3 a2 a1 a0 b3 b2 b1 b0 | CarryOut s3 s2 s1 s0;
   Full_Adder ch ZERO  a0 b0  | c1       s0;
   Full_Adder cf c1    a1 b1  | c2       s1;
   Full_Adder cd c2    a2 b2  | c3       s2;
   Full_Adder cb c3    a3 b3  | CarryOut s3;
Endef;

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

/* Put up first input number */
Switch aa x3 '3' ZERO;
Switch ab x2 '2' ZERO;
Switch ac x1 '1' ZERO;
Switch ad x0 '0' ZERO;

/* Put up second input number */
Switch af y3 '9' ZERO;
Switch ag y2 '8' ZERO;
Switch ah y1 '7' ZERO;
Switch ai y0 '6' ZERO;

FourBit_Adder cc-cg  x3 x2 x1 x0 y3 y2 y1 y0 | CarryOut s3 s2 s1 s0;


/* Probe the outputs */
Probe ea CarryOut;

Probe ed s3;
Probe ee s2;
Probe ef s1;
Probe eg s0;

