2012-05-17 134 views
0

在這段代碼中,我試圖乘以16位數並得到32位輸出。代碼有錯誤。在行16位數字乘法

c<=c+a; 

編譯器提供了一個錯誤:?「着讀的方式輸出端口‘C’什麼是我的錯誤,謝謝

library ieee; 
    use ieee.std_logic_1164.all; 
    use ieee.std_logic_arith.all; 
    use ieee.std_logic_unsigned.all; 

    entity circ is 
    port ( a :in std_logic_vector (15 downto 0); 
    b :in std_logic_vector (15 downto 0); 
    c :out std_logic_vector (31 downto 0) 
     ); 

    end entity; 

    architecture data of circ is 
    begin 
process(a,b) 
begin 
c<= '0'; 
for i in 15 to 0 loop 
if (b(i) = '1') then 
c<=c+a; 
end if; 
END LOOP; 

end process; 
    end data; 

回答

1

的錯誤是什麼編譯器告訴你

cant read port 'c' of mode out

您無法讀取的輸出。你正在閱讀c當你寫c <= c + a因爲c出現在賦值的右邊,你不得不重新寫如下代碼:

signal s : std_logic_vector(31 downto 0); 

process(a,b) 
begin 
    s <= (others => '0'); 
    for i in 15 to 0 loop 
    if (b(i) = '1') then 
     s <= s + a; -- Use a local signal that we can read and write 
    end if; 
    end loop; 
    c <= s; -- Assign the output to the local signal. 
end process; 
+0

在線 處使用Max plus II c <='0'; 編譯器給出的錯誤: '波形元素的類型必須是「std_logic_vector」' – redlogic

+0

'c <='0''應該是'c <=(others =>'0')'因爲它是std_logic_vector而不是std_logic –

+0

我沒有注意到那只是從OP的代碼中剪切和粘貼而已。我會解決的。 –