2013-07-23 53 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」'?我沒有模擬器,但我認爲這是語法... –