4 位幅度比较器 VHDL

问题描述 投票:0回答:2

我必须在 VHDL 中制作一个仅包含并发语句的 4 位幅度比较器(没有 if/else 或 case/when)。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity Exercise is
port (  A : in std_logic_vector (3 downto 0);
        B : in std_logic_vector (3 downto 0);
        Ag : out std_logic;
        Bg : out std_logic;
        AeqB: out std_logic
       );   
end Exercise;

architecture Comparator of Exercise is

begin
    Ag <= '1'when (A>B) else '0'; 
    Bg <= '1' when (B>A) else '0';  --Problem: Here if i sumulate B="ZZZZ", Bg is 1, asi if B>A 
    AeqB<= '1' when (A=B) else '0'; 
end Comparator; 

问题是我需要计算 std_logic 的所有其他值(U,X,Z,W,L,H,-),我知道有

others
但不知道如何制作带有
with/select
语句的比较器。

谢谢

vhdl comparator magnitude
2个回答
0
投票

通常,您可以使用

0
函数将 std_logic 可以采用的各种值“转换”为
1
to_01
。我认为它在包装中
numeric_std


0
投票
library IEEE;

    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.STD_LOGIC_ARITH.ALL;
    use IEEE.STD_LOGIC_UNSIGNED.ALL;

    entity comp_4 is
    port (  A:IN STD_LOGIC_VECTOR(0 to 3);
        B:IN STD_LOGIC_VECTOR(0 to 3);
        ET:OUT STD_LOGIC;
        GT:OUT STD_LOGIC;
        LT:OUT STD_LOGIC);

    end comp_4;

    architecture dataflow of comp_4 is

    begin
    with A-B(0 to 3) select

    ET <=   '1' when "0000",
        '0' when others;

    with A > B select

    GT <=   '1' when true,
        '0' when others;

    with A < B select

    LT <=   '1' when true,
        '0' when others;

    end dataflow;
© www.soinside.com 2019 - 2024. All rights reserved.