2014-02-18 109 views
0
library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 

entity mux is 
port (sel: in std_logic; 
     s0,s1: in std_logic_vector (3 downto 0) ; 
     sout : out std_logic_vector (3 downto 0)); 
end mux; 

architecture Behavioral of mux is 

begin 
if sel = '0' then 
    sout <= s0; 
else 
    sout <= s1; 
end if; 

end Behavioral; 

- 我試圖做一個多路複用器的四位串行加法器輸出。如果cin爲0,那麼它將採用來自第一個加法器的總和爲 - 其中cin爲0,如果cin爲1,那麼它將從我用cin1喂入的第二加法器中獲得總和。然而,如果某處我無法確定 - out,這是一個錯誤。編譯器說錯誤附近,如果其他和結束語句VHDL如果聲明錯誤

回答

1

if是一個順序語句,所以它只能在process內。與when更換if,因爲這是這樣可以直接在建築中使用的併發聲明:

sout <= s0 when (sel = '0') else s1; 
1

使用的if-else與適當的靈敏度列表中的過程中構建。

`

process(sel) 
begin 
(
    if sel = '0' then 
     sout <= s0; 
else 
    sout <= s1; 
end if; 
); 
end process; 

其他使用When Else構建