【问题标题】:VHDL directly comparing vectorsVHDL直接比较向量
【发布时间】:2014-05-26 20:46:07
【问题描述】:

我想知道是否可以直接比较 2 个向量,而不是逐个查看它们。

例如:

entity Comparator is
port(a,b in: std_logic_vector (2 downto 0);
     out1, out2 out: std_logic);
end Comparator;

architecture behavioural of Comparator1 is
begin
    if a = b then
        out1 <= '1'
    else if /= then
        out2 <= '1'
    end if;
end behaviour;

这可能吗?

【问题讨论】:

    标签: vector vhdl comparator


    【解决方案1】:

    答案是肯定的,可以直接比较同类型和子类型指示的两个数组类型。

    但是您的示例代码无效。

    表达式a=b 的结果是布尔值。您可以通过分配out1out2 将其转换为std_logic。此上下文中的 if 语句必须在流程语句中。你也不需要两个输出:

    architecture foo of Comparator1 is
    begin
    UNLABELED:
        process (a,b)
        begin
            if a = b then
                out1 <= '1';
            else 
                out1 <= '0';
            end if;
        end process;
    end architecture;
    

    另一种并发信号赋值语句,一个条件信号赋值,其过程与上述等效:

    architecture fum of Comparator1 is
    begin
    UNLABELED:
        out1 <= '1' when a = b else '0';
    end architecture;
    

    【讨论】:

    • 非常感谢,正是我想要的! :D
    • 我认为这仅在 VHDL-2008 中有效:/
    • @mikelsr 你的想法不正确。原始 -1987 标准和后续版本支持并发条件信号分配语句(如图所示)。 -2008 年引入了顺序条件信号赋值语句。两种架构都使用 -1993 进行了验证。
    • @user1155120 我的错
    【解决方案2】:

    您也可以使用to_integer(unsigned(a)) 并以整数形式威胁它们。 例如:

    IF(to_integer(unsigned(a)) < to_integer(unsigned(b))) THEN
    

    【讨论】:

    • 这里有个问题,为什么要麻烦to_integer?我不能这样做: IF(unsigned(a)
    • @nirvanaswap 与this link 相关,您只能比较std_logic_unsignedstd_logic_signed。假设 unsigned(...) 仅使用 unsigned(...)(或 signed(...))正确转换类型应该也可以工作。
    猜你喜欢
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-04
    • 2013-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多