VHDL中的数组类型不匹配

我的VHDL代码非常简单的问题。我已经定义了以下代码:
type irf_array is array(0 to 1) of integer;
signal index : std_logic;
....
index := input(5);
out   := irf_array(index);
当试图编译这个简单的代码片段时,我得到以下错误:
Error: array index type mismatch [6.4]
所以我想知道是否有人知道如何使用std_logic值作为我的数组的输入。 非常感谢!     
已邀请:
您的数组索引必须是整数。如果要使用基于std_logic的类型,则应该使用有符号或无符号类型(包括数值的概念,与普通的std_logic信号不同)和适当的类型转换:
type irf_array is array(0 to 1) of integer;
signal index : unsigned(0 downto 0);
....
index(0) := input(5);
out   := irf_array(to_integer(index));
您可以使用std_logic_vector而不是unsigned类型,并进行额外的转换:
signal index : std_logic_vector(0 downto 0);
...
out   := irf_array(to_integer(unsigned(index)));
    

要回复问题请先登录注册