bit_vector 静态常量越界

bit_vector bounds violation by static constant

在 SO 而不是 EE 上发布这个问题是因为我正在努力解决 coding/software 缺陷。


我是 VHDL 新手,正在阅读 "Free range VHDL" 书。玩 bit_vector 我发现在总线语法中访问单线遵循 bus_name(0) (0 只是为了举例)。

牢记这一点,我编写了 4 输入多路复用器的简单表示。

library ieee;
use ieee.std_logic_1164.all;

entity Multiplexer4_1 is
port
(   
    data    : in bit_vector(3 to 0);
    selector    : in bit_vector(1 to 0);
    output  : out bit
);
end entity Multiplexer4_1;

architecture m4_1 of Multiplexer4_1 is
begin
    output <= data(3) when (selector = "11") else
        data(2) when (selector = "10") else
        data(1) when (selector = "01") else
        data(0) when (selector = "00") else
        '0';
end architecture m4_1;

我正在使用 ghdl 通过以下命令在 linux 下处理 VHDL。

ghdl -a 4Multiplexer.vhdl

因此,我收到 4 条错误消息,显然是因为 data(0)data(1) 和其他原因,如下所列。

4Multiplexer.vhdl:15:23: static constant violates bounds
4Multiplexer.vhdl:16:21: static constant violates bounds
4Multiplexer.vhdl:17:21: static constant violates bounds
4Multiplexer.vhdl:18:21: static constant violates bounds
ghdl: compilation error

题目是:


更新:

不要重蹈我的覆辙,了解 arrays/ranges 在 VHDL 中的工作方式至关重要。

感谢帮助!

问题出在声明上。

您已将数据和选择器定义为

data    : in bit_vector(3 to 0);
    selector    : in bit_vector(1 to 0);

您应该将其定义为

data    : in bit_vector(3 downto 0);
selector    : in bit_vector(1 downto 0);

data    : in bit_vector(0 to 3);
selector    : in bit_vector(0 to 1);

to 和 downto 的区别:

link 已经解释了 to 和 downto 之间的区别。 "downto" 和 "to" 的任何区别都出现在我们不仅要使用位向量来表示位数组(其中每个位都有独立的行为),而且要表示整数时。然后,由于加法器、乘法器等电路处理数字的方式不同,位的重要性也有所不同。 我再举一个例子

假设你想分配你的位向量值=“0001” 如果使用“3 downto 0”,赋值将为

data<=(0 => '1', others => '0')

在“0 到 3”的情况下,赋值将为

data<=(3=>'1',others => '0')

重要的是,应该始终坚持上升或下降范围。程序员可以结合使用两者。但是,它可能会造成混淆并引发一些错误。另外,据我所知,大多数公交车都是使用降序编号的。因此,程序员喜欢递减范围。