用VHDL索引数组

Cor*_* G. 3 vhdl

我有一个数组:

type offsets_type is array (4 downto 0) of std_logic_vector (4 downto 0); 
signal av     : offsets_type;
Run Code Online (Sandbox Code Playgroud)

我想这样做,基本上:av[addr] += 1;
但这一行:

 av(to_integer(unsigned(addr))) <= unsigned(av(to_integer(unsigned(addr))) + 1;
Run Code Online (Sandbox Code Playgroud)

产生此错误:
to_integer can not have such operands in this context.

我也试过使用conv_integer,但这给出Wrong type of index了一个错误.

有解决方案吗 谢谢.

Phi*_*ppe 13

您的代码中存在一些问题:

  1. 您将计算结果转换为a unsigned,而左侧则为std_logic_vector
  2. 数据类型可能有问题addr,但您尚未与我们分享.
  3. 作业中缺少一个右括号.

如果在类型定义中使用"unsigned",将会更容易.这样,您表示位模式实际上是您想要在整数运算中使用的东西.

type offsets_type is array (4 downto 0) of unsigned (4 downto 0);
signal av     : offsets_type;
signal addr :unsigned(2 downto 0);
Run Code Online (Sandbox Code Playgroud)

这将为您节省一些类型转换:

av(to_integer(addr)) <= av(to_integer(addr)) + "1";
Run Code Online (Sandbox Code Playgroud)

编辑:你确实使用过ieee.numeric_std.all不是吗?

  • @Pwngulator我建议你使用`ieee.numeric_std.all`库(而不是`std_logic_unsigned`).该库具有转换函数`to_integer`. (3认同)