4
logic index : unsigned(9 downto 0) ;  
type fft_data  is array (3 downto 0) of unsigned(16 downto 0);  
signal tmp,signal fmax_data :fft_data;  
tmp = fmax_data(to_integer(index(9)));

以上部分代码给出了以下编译错误;“子程序调用或运算符参数类型不匹配 87”

如果我进行以下修改,它会起作用。

logic index : unsigned(9 downto 0) ;  
type fft_data  is array (3 downto 0) of unsigned(16 downto 0);  
signal tmp,signal fmax_data :fft_data;;  
tmp = fmax_data(to_integer(index(**9 downto 9**)));

谁能解释一下上述两种实现有什么区别?我正在使用 vhdl-93 标准和 ncvhdl。谢谢

4

1 回答 1

4

numeric_std中,该 to_integer函数只为unsignedsigned类型定义。

无符号派生自std_logicastype UNSIGNED is array ( NATURAL range <> ) of STD_LOGIC;

当您使用时,to_integer(index(9))您正在传递index(9)类型为std_logic.

当您使用时,to_integer(index(9 downto 9))您传递的是一个大小为 1 的范围index但是,它是一种unsigned类型。

如果需要,您还可以创建自定义函数。转换std_logicinteger.

function to_integer (ARG : std_logic)
  return integer is
begin
  if ARG = '1' OR ARG = 'H' then
    return 1;
  else
    return 0;
  end if;
end function to_integer;`

或环绕to_integer

function to_integer (ARG : std_logic)
    return integer is
    variable t : unsigned(0 downto 0) := "0";
begin
    t(0) := ARG;
    return to_integer(t);
end function to_integer;
于 2017-07-03T07:55:53.753 回答