gpt4 book ai didi

vector - VHDL 直接比较向量

转载 作者:行者123 更新时间:2023-12-04 23:50:23 24 4
gpt4 key购买 nike

我想知道是否可以直接比较 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com