-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparator.vhd
60 lines (50 loc) · 1.21 KB
/
comparator.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity comparator is
Port ( a : in STD_LOGIC_VECTOR (7 downto 0);
b : in STD_LOGIC_VECTOR (7 downto 0);
c : out STD_LOGIC;
mode : in STD_LOGIC_VECTOR (1 downto 0));
end comparator;
architecture Behavioral of comparator is
signal a_un : unsigned (7 downto 0);
signal b_un : unsigned (7 downto 0);
constant MODE_GREATER : std_logic_vector(1 downto 0) := "00";
constant MODE_LESS : std_logic_vector(1 downto 0) := "01";
constant MODE_EQUAL : std_logic_vector(1 downto 0) := "10";
constant MODE_INEQUAL : std_logic_vector(1 downto 0) := "11";
begin
a_un <= unsigned(a);
b_un <= unsigned(b);
process (mode, a_un, b_un) begin
case mode is
when MODE_GREATER =>
if b_un > a_un then
c <= '1';
else
c <= '0';
end if;
when MODE_LESS =>
if b_un < a_un then
c <= '1';
else
c <= '0';
end if;
when MODE_EQUAL =>
if b_un = a_un then
c <= '1';
else
c <= '0';
end if;
when MODE_INEQUAL =>
if b_un /= a_un then
c <= '1';
else
c <= '0';
end if;
when others =>
c <= '0';
end case;
end process;
end Behavioral;