在 VHDL 中,当作为参数传递给函数/过程时,不受约束数组的索引范围默认为什么?



我使用的函数返回一个用户定义的无约束数组:

type t_array is array(integer range <>) of std_logic_vector(7 downto 0);

然后将此数组传递给过程。在我的过程或函数中,没有任何地方明确定义数组的范围。

当数组作为参数传递时,它的索引范围默认为什么?

它将默认为与参数关联的任何值。因此,在这个例子中:

library IEEE;
use IEEE.std_logic_1164.all;
entity E is
end entity ;
architecture A of E is
type t_array is array(integer range <>) of std_logic_vector(7 downto 0);
procedure P (constant I : in t_array) is
begin
report integer'image(I'left);
report integer'image(I'right);
end procedure;
begin
process
variable V : t_array(0 to 9);
begin
P(V);
wait;
end process;
end architecture A;

这将显示:

# EXECUTION:: NOTE   : 0
# EXECUTION:: Time: 0 ps,  Iteration: 0,  Instance: /E,  Process: line__19.
# EXECUTION:: NOTE   : 9
# EXECUTION:: Time: 0 ps,  Iteration: 0,  Instance: /E,  Process: line__19.

https://www.edaplayground.com/x/2zNy


假设您不知道输入的范围是什么,与其在代码中添加'left'right属性,并使用todownto进行完全的处理,有时有助于对输入进行规范化,例如:

procedure P (constant I : in t_array) is
variable normalised_I : t_array(1 to I'length) := I;
begin
...
end procedure;

最新更新