-- This procedure adds two bit_vectors and a carry and returns a sum -- and a carry. Both bit_vectors should be of the same length. procedure Addvec2 (Add1,Add2: in bit_vector; Cin: in bit; signal Sum: out bit_vector; signal Cout: out bit) is variable C: bit := Cin; alias n1 : bit_vector(Add1'length-1 downto 0) is Add1; alias n2 : bit_vector(Add2'length-1 downto 0) is Add2; alias S : bit_vector(Sum'length-1 downto 0) is Sum; begin assert ((n1'length = n2'length) and (n1'length = S'length)) report "Vector lengths must be equal!" severity error; for i in s'reverse_range loop S(i) <= n1(i) xor n2(i) xor C; C := (n1(i) and n2(i)) or (n1(i) and C) or (n2(i) and C); end loop; Cout <= C; end Addvec2;