2016-09-21 20 views
0

有人可以幫助我如何將此vhdl代碼更改爲使用'when'語句?如何更改爲何時聲明

下面是代碼我寫:

library IEEE; 
use IEEE.std_logic_1164.all; 

entity sel2_1 is 
    port(A, B, SEL : in std_logic; 
     outsgnl : out std_logic); 
end sel2_1; 

architecture EX1 of sel2_1 is 
begin 
    outsgnl <= (not SEL and A) or (SEL and B); 
end EX1; 

的模擬結果如下: simulation

+0

我已經編輯了上面的問題,並把模擬結果。我試圖改變vhdl代碼使用時聲明和我期望相同的確切結果。 – HAKIM

回答

2

當關鍵字在不同VHDL分配被使用。假設SEL'0''1'則可以通過一個選擇的信號分配 simpley取代

outsgnl <= (not SEL and A) or (SEL and B); 

,通常被稱爲與/選擇分配

with SEL select outsgnl <= 
    A when '0', 
    B when others; 

或者,也可以使用條件信號分配常簡稱當/別

outsgnl <= A when SEL = '0' else B; 
+0

非常感謝你!它與我上面發佈的模擬功能相同。 – HAKIM