vector - VHDL 直接比较向量

标签 vector vhdl comparator

我想知道是否可以直接比较 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;
这可能吗?

最佳答案

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

但是您的示例代码无效。

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

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;

关于vector - VHDL 直接比较向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23877501/

相关文章:

c++ - 自定义对象的vector如何设置大小?

c++ - (C++) 用于检查对象是否在 vector/数组/列表/...中的模板?

c++ - 3个 vector 的高效排序算法

Java map : Reverse chronological order

java - 在 Java 集合排序中使用 Comparator 接口(interface)比较方法返回值 -1, 0, 1 到底意味着什么?

c++ - "fixed"大小的 vector 在 C++ 中是否也有错误的大小(与内存大小相比)

vhdl - 将 n 个长位逻辑向量拆分为 n 个单独的二进制值

concurrency - 请澄清VHDL中顺序和并发执行的概念

vhdl - 这段代码会产生多少个触发器?

java - 为什么当 Comparator.compare 相等时我们需要返回 0