Simple examples of converting to binary bit lane form: | pandex w (Num n) = if n = 0 then [ x_false ] else let fun k 0 = nil (* lsb first *) | k n = (if (n mod 2)=1 then x_true else x_false) :: k (n div 2) fun q 0 = [x_true] (* final negative sign bit *) | q n = (if (n mod 2)=0 then x_true else x_false) :: q (n div 2) in if (n >= 0) then k n else sex w (q (0-1-n)) end Example: -4 in a 6 bit field is 111100. > pandex 6 (Num ~4) it = [ x_false, x_false, x_true, x_true, x_true, x_true ] Hold lists least significant bit first to make adders easier! Example: conditional expression: a broadside multiplexor: | pandex w (Query(g, t, f)) = let val t' = pandex w t val f' = pandex w f fun k([], []) = [] | k(a, nil) = k(a, [ false ]) | k(nil, b) = k([ false ], b) | k(a::at, b::bt) = gen_mux2(g, a, b) :: k(at, bt) in k(t', f') end > pandex 3 (Query(Net "g", [Net "t0", Net "t1"], [Num 5])) MUX2(u10, g, t0, VCC); MUX2(u11, g, t1, GND); MUX2(u12, g, GND, VCC); it = [ Net "u10", Net "u11", Net "u12" ] Or if we have some simple peepholes enabled we get: > pandex 3 (Query(Net "g", [Net "t0", Net "t1"], [Num 5])) MUX2(u20, g, t0, VCC); AND2(u21, g, t1); INV(u22, g) it = [ Net "u20", Net "u21", Net "u22" ] Exercise: write the pandex clauses for the left and right shift operators.