library IEEE;
use IEEE.std_logic_1164.all;

entity ADDER4 is
    port ( A, B: in  STD_LOGIC_VECTOR(3 downto 0);
           CI:   in  STD_LOGIC;
           S:    out STD_LOGIC_VECTOR(4 downto 0) );
end ADDER4;

architecture ADDER4_arch of ADDER4 is

component FA port ( A, B, CI: in  STD_LOGIC;
                    S, CO:    out STD_LOGIC );
end component;

signal C: STD_LOGIC_VECTOR(0 to 4);
begin
  C(0) <= CI;
  U1: for i in 0 to 3 generate
    U1C: FA port map (A(i), B(i), C(i), S(i), C(i+1));
  end generate;
  S(4) <= C(4);
end ADDER4_arch;
