2013-07-23 52 views
3

的范围我有两个二维数组:VHDL - 确定二维数组

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

真的是'0 downto 10'吗?它可能是'10'0或'0到10'。 – nio

+0

你能否用你的生成语句显示你的代码? – nio

+0

@nio oops,是的,它意味着'0到10'。我编辑了这篇文章。 – alexdavey

回答

7

array1x1D:

VHDL-2002:A亚型是必需的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:

array2D'range(1)array2D'range(2)访问不同的尺寸通过一个索引'range,从而 。

2
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阵列的向量元素的长度而没有中间信号/常数/该类型的可变..

+0

如何分配实际二维数组中的std_logic_vector,因为使用这两个索引只会将我们限制为一个std_logic值,仅使用一个索引是不够的 – quantum231

+1

@ quantum231:你的意思是'array2d(0,0到5) <=“01010”'?我没有模拟器,但我认为这是语法... –