/* 1 bit ALU  macroc
   Syntax: One_Bit_ALU a b carry_in sel1 sel0 | z carry_out;
   sel1 = 0, sel0 = 0 -> Add a, b carry_in
   sel1 = 0, sel0 = 1 -> Not a
   sel1 = 1, sel0 = 0 -> a Or b
   sel1 = 1, sel0 = 1 -> a AND b
*/

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 One_Bit_ALU a b c_in s[1..0] | z c_out;
 /* ========================
    Compute all outputs
    ======================== */
 Full_Adder aa a b c_in | c_out Out_Sum;
 Not aa a Out_Not;
 And aa a b Out_And;
 Or  aa a b Out_Or;

 /* =============================
    Select the desired output
    ============================= */
 Mux ab s[1] s[0] |  Out_Or  Out_And  Out_Not  Out_Sum | z ;

Endef;



/* -------------------
   Carry in
   ------------------- */
Switch 1a c 'c' ZERO;

/* ---------------------------
   a = input 1, b = input 2
   --------------------------- */
Switch 3a a 'a' ZERO;
Switch 4a b 'b' ZERO;

/* -------------------
   Controls
   ------------------- */
Switch 6a y '1' ZERO;
Switch 7a x '0' ZERO;

One_Bit_ALU 2b-5b a b c y x| z c_out;

Probe 3c z;
Probe 1c c_out;

