summaryrefslogtreecommitdiff
path: root/minijazz/test/nadder.mj
blob: a5a6a1783e3e2f455c157f4dd09874ff0ad516d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fulladder(a,b,c) = (s, r) where
  s = (a ^ b) ^ c;
  r = (a & b) + ((a ^ b) & c);
end where

adder<n>(a:[n], b:[n], c_in) = (o:[n], c_out) where
  if n = 0 then
    o = [];
    c_out = 0
  else
    (s_n1, c_n1) = adder<n-1>(a[1..], b[1..], c_in);
    (s_n, c_out) = fulladder(a[0], b[0], c_n1);
    o = s_n . s_n1
  end if
end where

main(a:[2], b:[2]) = (o:[2], c) where
  (o, c) = adder<2>(a,b,0)
end where