The following is a function call that counts the number of Z
The following is a function call that counts the number of ZERO’s in a 16 bit word. Write VHDL code for this function.
signal WORD: bit_vector(15 downto 0);
…
begin
WORD_0 <= COUNT_ZEROS(WORD);
…
begin
Solution
library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_unsigned.all; entity count_zeros is port( Sin: in std_logic_vector( 15 downto 0 ); count: out integer ); end count_zeros; architecture arch of count_zeros is begin process(Sin) variable temp: Integer:=0; begin labelloop: for i in 0 to 15 loop if( sin(i) = \'0\') then temp := temp + 1; end if; end loop; COUNT <= temp; end process; end arch;