adder5lf_exp.vhd
--
-- 5-bit adder (expand for-generate loop / logical equation)
--
library ieee;
use ieee.std_logic_1164.all;
entity adder5lf_exp is
port( a : in std_logic_vector(4 downto 0);
b : in std_logic_vector(4 downto 0);
ci : in std_logic;
co : out std_logic;
s : out std_logic_vector(4 downto 0) );
end adder5lf_exp;
architecture rtl of adder5lf_exp is
signal interCarry : std_logic_vector(4 downto 1);
begin
co <= (a(4) and b(4) ) or ( (a(4) or b(4) ) and interCarry(4) );
s(4) <= a(4) xor b(4) xor interCarry(4);
interCarry(4) <= (a(3) and b(3) ) or ( (a(3) or b(3) ) and interCarry(3) );
s(3) <= a(3) xor b(3) xor interCarry(3);
interCarry(3) <= (a(2) and b(2) ) or ( (a(2) or b(2) ) and interCarry(2) );
s(2) <= a(2) xor b(2) xor interCarry(2);
interCarry(2) <= (a(1) and b(1) ) or ( (a(1) or b(1) ) and interCarry(1) );
s(1) <= a(1) xor b(1) xor interCarry(1);
interCarry(1) <= (a(0) and b(0) ) or ( (a(0) or b(0) ) and ci);
s(0) <= a(0) xor b(0) xor ci;
end rtl;