2014-01-21 187 views
2

誰能告訴我爲什麼這個代碼不能被模擬。行爲檢查語法是正確的。我試圖創建一個整數的二維數組,這是不變的。VHDL整數二維數組

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.all; 
use IEEE.STD_LOGIC_ARITH.all; 

--selection function 1 

entity S1 is 
    Port ( 
    i : in STD_LOGIC_VECTOR (5 downto 0); 
    o : out STD_LOGIC_VECTOR (3 downto 0)); 
end S1; 

architecture Behavioral of S1 is 

    type matrix is array(0 downto 3, 0 downto 15) of INTEGER range 0 to 15; 
    constant m : matrix := 
     ((14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7), 
     (0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8), 
     (4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0), 
     (15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13)); 

    signal row : STD_LOGIC_VECTOR(1 downto 0); 
    signal col : STD_LOGIC_VECTOR(3 downto 0); 

begin 

    row <= i(5) & i(0); 
    col <= i(4 downto 1); 
    o <= conv_std_logic_vector(m(conv_integer(row), conv_integer(col)), 4); 

end Behavioral; 

解決方法:應該是(0到N)而不是(0 downto N)。錯誤消息不是很清楚。

+0

當你說它不能模擬你是什麼意思?它不運行嗎?或者它產生無效的結果?我看到的一件事是,你將2D矢量定義爲0 downto 3.這應該是3 downto 0.我不確定當你做倒退時會發生什麼。 – Russell

回答

7

您需要更好的語法檢查器。

GHDL報告:

ghdl -a --ieee=synopsys nullrange.vhd 
nullrange.vhd:18:7: too many elements associated 
nullrange.vhd:18:7: range length is beyond subtype length 
nullrange.vhd:18:7: too many elements associated 
nullrange.vhd:18:7: range length is beyond subtype length 
nullrange.vhd:19:6: too many elements associated 
nullrange.vhd:19:6: subaggregate length mismatch 
nullrange.vhd:20:6: too many elements associated 
nullrange.vhd:20:6: subaggregate length mismatch 
nullrange.vhd:21:6: too many elements associated 
nullrange.vhd:21:6: subaggregate length mismatch 
nullrange.vhd:17:10: default value length does not match object type length 
ghdl: compilation error 

(0 DOWNTO 3)被稱爲 「空範圍」,其是合法的,但沒有任何成員。所以初始化集合中有太多的元素...

+0

謝謝。然後我應該用case語句來實現它。 – crow

+1

不一定。扭轉範圍'(3 downto 0)'或它們的方向'(0到3)'可能會更容易。 –

+0

謝謝,我明白是什麼問題。這個錯誤信息的形式不是很清楚。 – crow