Comparators


comparators use two or more input values and a number of different comparison conditions built from the relational and logical operators.

the result of the comparison is given in the binary logic - output signal equals :'0' or '1'


Simple comparator (its instantiation)

library IEEE;

use IEEE.std_logic_1164.all;

use IEEE.numeric_std.all;

entity comp_eq is

    generic (size_in: integer);

    port (a,b: in unsigned (size_in-1 downto 0); eq: out std_logic);

end comp_eq;

architecture process_comp of comp_eq is

begin

process(a, b)

begin

    eq <='1'; -- initial value : equality

    for i in 0 to size_in-1 loop

      if (a(i) /= b(i)) then

          eq <='0';

          exit;

      else

        null;

      end if;

    end loop;

end process;

end process_comp;


and its instantiations in a structural architecture :

library IEEE;

use IEEE.std_logic_1164.all;

use IEEE.numeric_std.all;

entity str_comp is

    port (

      in_a, in_b: in unsigned (4 downto 0);

      in_c, in_d: in unsigned (7 downto 0);

      eq_ab, eq_cd: in std_logic);

end str_comp;

architecture structural of str_comp is

component comp_eq is

    generic (size_in: integer);

    port (a,b: in unsigned (size_in-1 downto 0); eq: out std_logic);

end component;

begin

comp_5:comp_eq -- comparator width-5 instantiation

      generic map(5)

      port map(in_a, in_b, eq_ab);

comp_8:comp_eq -- comparator width-8 instantiation

      generic map(8)

      port map(in_c, in_d, eq_cd);

end structural;