设计一个4选1数据选择器,输入端口为abcd,控制端为sel,输出端口为y。分别用选择信号赋值语句和case语句
下面是使用选择信号赋值语句实现 4 选 1 数据选择器的示例代码:
-- 4选1数据选择器
entity data_selector is
port(
a, b, c, d : in std_logic;
sel : in std_logic_vector(1 downto 0);
y : out std_logic
);
end data_selector;
architecture behavioral of data_selector is
begin
with sel select
y <= a when "00",
b when "01",
c when "10",
d when "11";
end behavioral;
下面是使用 case 语句实现 4 选 1 数据选择器的代码:
-- 4选1数据选择器
entity data_selector is
port(
a, b, c, d : in std_logic;
sel : in std_logic_vector(1 downto 0);
y : out std_logic
);
end data_selector;
architecture behavioral of data_selector is
begin
process(a, b, c, d, sel)
begin
case sel is
when "00" => y <= a;
when "01" => y <= b;
when "10" => y <= c;
when "11" => y <= d;
when others => y <= '0';
end case;
end process;
end behavioral;
希望这些信息能帮到你!