forked from ZIKOAR/32-bit-processor-with-vhdl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparator_32_bits.vhd
40 lines (30 loc) · 1016 Bytes
/
comparator_32_bits.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
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity comparator_32_bits is
port (
a, b : in std_logic_vector(31 downto 0);
r : out std_logic_vector(31 downto 0)
);
end entity;
architecture comparator_32_bits_arch of comparator_32_bits is
signal a_signed, b_signed : signed(31 downto 0);
signal res : std_logic_vector(1 downto 0);
begin:
a_signed <= signed(a);
b_signed <= signed(b);
process(a_signed, b_signed)
begin
if a_signed = b_signed then
res <= "00";
elsif a_signed > b_signed then
res <= "01";
else
res <= "10";
end if;
end process;
r <=
(others => '0') when res = "00" else -- 00000000000000000000000000000000
(0 => '1', others => '0') when res = "01" else -- 00000000000000000000000000000001
(others => '1'); -- 11111111111111111111111111111111
end architecture;