如何索引到 vhdl std_logic_vector?

Jim*_*Bob 3 vhdl

我有以下声明:

signal count:STD_LOGIC_VECTOR (3 downto 0);
signal txbuff:STD_LOGIC_VECTOR (7 downto 0);
Run Code Online (Sandbox Code Playgroud)
  1. dout 是一个std_logic输出
  2. 我正在使用IEEE.NUMERIC_STD.ALL

我想使用向量计数作为 txbuff 的索引。我尝试过的许多事情包括:

count<=std_logic_vector(unsigned(count)-1);
dout<=txbuff(unsigned(count));
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

第 99 行。 txbuff 的索引类型错误。

Bri*_*ond 5

您需要一个整数作为索引类型。(或者对于其他数组,您可以使用任何离散类型,例如枚举)。

其他答案已经向您展示了如何使用类型转换函数到达那里:我会问,为什么不让“计数”成为一个整数,就像natural range 0 to 15首先一样?它将以相同的方式综合,并使代码更简洁。