在 VHDL 中,当作为参数传递给 function/procedure 时,无约束数组的索引范围默认为什么?
In VHDL, what does an unconstrained array's index range default to when passed as an argument to a function/procedure?
我正在使用 returns 用户定义的无约束数组的函数:
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
属性来填充您的代码并使用 to
和 downto
,它有时有助于规范化输入,例如:
procedure P (constant I : in t_array) is
variable normalised_I : t_array(1 to I'length) := I;
begin
...
end procedure;
我正在使用 returns 用户定义的无约束数组的函数:
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
属性来填充您的代码并使用 to
和 downto
,它有时有助于规范化输入,例如:
procedure P (constant I : in t_array) is
variable normalised_I : t_array(1 to I'length) := I;
begin
...
end procedure;