---------------------------------------------------------------------- -- node Adder ---------------------------------------------------------------------- node Adder (A,B,Cin : bool) returns (S,Cout : bool); let S = A xor B xor Cin; Cout = (A and B) or (B and Cin) or (A and Cin); tel ---------------------------------------------------------------------- -- node ArrayAdder -- example of FourbitAdder (with no carry-in) using arrays -- S[0] index (statically only) -- S[1..3] slice -- expands arrays into multiple variables -- (S[1..3],C[1..3]) = Adder(A[1..3],B[1..3],C[0..2]) becomes -- (S[1],C[1]) = Adder(A[1],B[1],C[0]); -- (S[2],C[2]) = Adder(A[2],B[2],C[1]); -- (S[3],C[3]) = Adder(A[3],B[3],C[2]); ---------------------------------------------------------------------- node ArrayAdder (A,B: bool^4) returns (S: bool^4; carry:bool); var C:bool^4; let (S[0],C[0]) = Adder(A[0],B[0],false); (S[1..3],C[1..3]) = Adder(A[1..3],B[1..3],C[0..2]); carry = C[3]; tel ---------------------------------------------------------------------- -- node GeneralAdder -- example of n-bit adder (with no carry-in) using arrays -- n must be defined at compile-time ---------------------------------------------------------------------- node GeneralAdder (const n:int; A,B: bool^n) returns (S: bool^n; carry:bool); var C:bool^n; let (S[0],C[0]) = Adder(A[0],B[0],false); (S[1..n-1],C[1..n-1]) = Adder(A[1..n-1],B[1..n-1],C[0..n-1]); carry = C[n-1]; tel