Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------ count_ones ---------
- Library ieee;
- use ieee.std_logic_1164.all;
- use ieee.numeric_std.all;
- entity count_ones is
- port(
- A : in std_logic_vector(7 downto 0);
- ones : out std_logic_vector(3 downto 0));
- end count_ones;
- architecture structural of count_ones is
- begin
- count: process(A) -- Counter process initieres
- variable countA : integer; -- Counter variabel defineres
- begin
- countA := 0; -- Counter varibel resettes
- for index in 7 downto 0 loop -- Loop som gentager sig 8 gange
- if (A(index) = '1') then -- Tester om vores A-input er 1 eller ikke
- countA := countA + 1; -- Hvis A = 1, så stiger vores counter
- else
- end if;
- end loop;
- ones <= std_logic_vector(to_unsigned(countA, ones'length)); -- Counteren konverteres til en vector,
- end process; -- da input på bin2hex er en vector
- end structural;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement