library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity Vcnt1s is port ( D: in STD_LOGIC_VECTOR (31 downto 0); SUM: out STD_LOGIC_VECTOR (4 downto 0) ); end Vcnt1s; architecture Vcnt1s_arch of Vcnt1s is begin process (D) variable S: STD_LOGIC_VECTOR(4 downto 0); begin S := "00000"; for i in 0 to 31 loop if D(i) = '1' then S := S + "00001"; end if; end loop; SUM <= S; end process; end Vcnt1s_arch;