Design an 8-bit comparator that would compare two 8-bit values. Your comparator
ID: 3563480 • Letter: D
Question
Design an 8-bit comparator that would compare two 8-bit values. Your comparator must have the following 3 outputs: equal, less-than, greater-than. Your design must be done in TWO different ways:
This is what I have so far. I also need a testbench to simulate this.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity cmp8 is
port (
a,b : in std_logic_vector(7 downto 0);
aeqB, altb, agtb : out std_logic
);
end cmp8;
architecture a of cmp8 is
begin
if(a=b) then agtb<='0';altb<='0';aeqb<='1';
elsif(a<b) then agtb<='0';altb<='1';aeqb<='0';
else agtb<='1';altb<='0';aeqb<='0';
end if;
end process a;
end behavioral;
Explanation / Answer
VHDL model of comparator (8 bits):
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
-- 8 Bit Unsigned Comparator
entity cmp8 is
port (
A,B : in std_logic_vector(7 downto 0);
aeqb, altb, agtb : out std_logic
);
end cmp8;
architecture a of cmp8 is
begin
aeqb <= '1' when (a = b) else '0';
altb <= '1' when (a < b) else '0';
agtb <= '1' when (a > b) else '0';
end;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.