我是VHDL的新手,我正在嘗試寫一個左移位器,它需要一個32位值和一個5位值。左移位器然後試圖通過移出左邊的5位數字指定的位數並將右邊的多個零移出來來執行32位值的邏輯左移。我不明白爲什麼數組表示法不起作用。 1 < < 1的結果產生20000000而不是00000002.有人可以解釋我要去哪裏出錯嗎?下面的代碼:爲什麼VHDL不能移動工作?
SIGNAL lshiftOutput : STD_LOGIC_VECTOR(31 downto 0);
COMPONENT Lshift32
Port(a : in STD_LOGIC_VECTOR(31 downto 0);
b : in STD_LOGIC_VECTOR(4 downto 0);
lshiftOutput : out STD_LOGIC_VECTOR(31 downto 0));
END COMPONENT;
PROCESS( a, b, opcode, adderOutput, subtractOutput, xorOutput, lshiftOutput, rshiftOutput)
BEGIN
IF opcode = "0000" THEN
result <= x"00000000";
ELSIF opcode = "0001" THEN
result <= adderOutput;
ELSIF opcode = "0010" THEN
result <= subtractOutput;
ELSIF opcode = "0011" THEN
result <= NOT a;
ELSIF opcode = "0100" THEN
result <= a AND b;
ELSIF opcode = "0101" THEN
result <= a OR b;
ELSIF opcode = "0110" THEN
result <= xorOutput;
ELSIF opcode = "0111" THEN
result <= lshiftOutput;
ELSIF opcode = "1000" THEN
result <= rshiftOutput;
END IF;
END PROCESS;
LIBRARY ieee;
USE ieee.std_logic_unsigned.ALL;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY Lshift32 IS
Port(a : in STD_LOGIC_VECTOR (31 downto 0);
b : in STD_LOGIC_VECTOR (4 downto 0);
lshiftOutput : out STD_LOGIC_VECTOR (31 downto 0));
END Lshift32;
ARCHITECTURE Lshift32Architecture of Lshift32 IS
BEGIN
PROCESS(a, b)
VARIABLE shiftAmount : INTEGER := 0;
BEGIN
shiftAmount := to_integer(b(4 downto 0));
-- Shift left
lshiftOutput <= a(31-shiftAmount downto 0) & (shiftAmount-1 downto 0 => '0');
END PROCESS;
END Lshift32Architecture;
該試驗檯是這樣的:
-- Shift Left -------------------------------------------------------
WAIT FOR 9 ns;
op <= "0111";
-- 1 << 1
input_a <= x"00000001";
input_b <= x"00000001";
WAIT FOR 1 ns;
IF (output /= x"00000002") THEN
ASSERT false REPORT "1 << 1 has incorrect result" severity error;
END IF;
包括其餘的代碼,包括庫/使用條款和據稱給你這個結果的測試臺。由於錯誤的移位距離可能會產生這種結果,因此您可能需要添加顯示「shiftAmount」的「報告」語句。 –
「測試平臺」(a)不完整,(b)測試與「Lshift32」實體完全不同的內容。發佈你正在抱怨的實體的單元測試 - 而不是其他的東西。 –