VHDL - 确定2D数组的范围

7

我有两个二维数组:

type array1x1D is array (0 to 10) of std_logic_vector(0 to 10); -- Array of arrays
type array2D is array (0 to 10, 0 to 10) of std_logic; -- Real 2D array

我该如何访问前者和后者中 std_logic_vectors 的范围?我当然可以使用一个变量来跟踪它们的大小,但我宁愿避免这样做。 我正在尝试使用 GENERATE 语句循环遍历数组。


真的是 0 downto 10 吗?它也可以是 10 downto 0 或者 0 to 10 - nio
请问您能否展示一下您的代码和生成语句? - nio
@nio 哎呀,是的,应该是“0到10”。我已经编辑了帖子。 - alexdavey
使用VHDL-2002,如果您有一个该类型的信号/变量/常量,例如data,您可以在第一种情况(数组的数组)中使用data(data'LEFT)'RANGE - aschipfl
2个回答

11

一维数组:

VHDL-2002:如果您想获取std_logic_vector(0 downto 10)部分的范围,需要为其指定子类型,从而将该类型分割为:

subtype array1x1D_element is std_logic_vector(0 to 10);
type array1x1D is array (0 to 10) of array1x1D_element; -- Array of arrays

然后您可以执行 array1x1D_element'range

VHDL-2008:使用添加的'element属性(可能是为此目的而添加的:-),并编写array1x1D'element'range

array2D:

通过对'range进行索引来访问不同的维度,因此可以使用array2D'range(1)array2D'range(2)


3
entity test1 is
end entity;
library ieee;
use ieee.std_logic_1164.all;
architecture a1 of test1 is
    type array1x1D is array (0 to 10) of std_logic_vector(0 to 10); -- Array of arrays
    type array2D is array (0 to 10, 0 to 5) of std_logic; -- Real 2D array
    signal s1 : array1x1D;
begin
    name : process is
    begin
        report "array1x1D(0)'length:" & integer'image(s1(0)'length);
        report "array2D'length(1):" & integer'image(array2D'length(1));
        report "array2D'length(2):" & integer'image(array2D'length(2));
        wait;
    end process name;
end architecture a1;

产生:

# run -all
# ** Note: array1x1D(0)'length:11
#    Time: 0 ns  Iteration: 0  Instance: /test1
# ** Note: array2D'length(1):11
#    Time: 0 ns  Iteration: 0  Instance: /test1
# ** Note: array2D'length(2):6
#    Time: 0 ns  Iteration: 0  Instance: /test1
#

我暂时无法立即找到一种方法来确定1D数组的向量元素长度,而不需要该类型的中间信号/常数/变量...


如何在实际的二维数组中分配std_logic_vector,因为使用两个索引将仅限制我们使用单个std_logic值,而仅使用一个索引则不足够。 - quantum231
1
@quantum231:你是指 array2d(0,0 to 5) <= "01010" 吗?我手头没有模拟器,但我认为这就是语法... - Martin Thompson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接