summaryrefslogblamecommitdiff
path: root/tests/nadder.mj
blob: 91caa6d5b7946f207f0d2b0495eb563edf48e1d5 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                   







                                                   
                
      

                                                     



                  

                                                             
         
const word_size = 8

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

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