1.思路
使用(完整)if控制语句:当sel=‘1’,将端口d0数据传给端口q,反之,将端口d1数据传给端口q,从而实现二选一电路
2.VHDL语言
library ieee;
use ieee.std_logic_1164.all;
entity mux2 is
port(d0 : in std_logic_vector(3 downto 0); --定义长度为4位的变量
d1 : in std_logic_vector(3 downto 0);
sel: in std_logic; --定义长度为1的逻辑变量
q : out std_logic_vector(3 downto 0)
);
end mux2;
architecture rtl of mux2 is
begin
process(d0,d1,sel)
begin
if(sel = '1') then --if else 完整的条件语句
q <= d0;
else
q <= d1;
end if;
end process;
end rtl;