Skip to content

Instantly share code, notes, and snippets.

@tonussi
Last active December 16, 2015 15:39
Show Gist options
  • Save tonussi/5457393 to your computer and use it in GitHub Desktop.
Save tonussi/5457393 to your computer and use it in GitHub Desktop.
n bit comp
--n bit_vector comparador
--tabela
-- = igualdade
-- /= ~ igualdade
-- < menor que
-- <= menor ou igual
-- > maior
-- >= maior ou igual
-- not negado
-- and e
-- or ou
-- xor exclusao mutua
library ieee;
use ieee.std_logic_1164.all;
entity comparador is generic (nBits: natural := 3);
port (
a: in std_logic_vector(nBits - 1 downto 0);
b: in std_logic_vector(nBits - 1 downto 0);
maior: out std_logic;
menor: out std_logic;
igual: out std_logic);
end comparador;
architecture bhv of comparador is begin
process (a, b) begin
maior <= '0';
igual <= '0';
menor <= '0';
if (a > b) then
maior <= '1';
elsif (a = b) then
igual <= '1';
elsif (a < b) then
menor <= '1';
end if;
end process;
end bhv;
force /a 000 0ns, 001 10ns, 010 20ns, 011 30ns, 100 35ns, 101 60ns, 110 70ns, 111 80ns
force /b 000 0 ns, 001 20ns, 010 40ns, 011 60ns, 100 80ns, 101 100ns, 110 120ns, 111 140ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment