--=====================================================
-- Проект 02. Мультиплексор 4 в 1
-- Три способа описания выбора: with-select, when-else
-- и процесс с case. Здесь показан with-select.
--=====================================================
library ieee;
use ieee.std_logic_1164.all;

entity mux4 is
    port (
        d       : in  std_logic_vector(3 downto 0);     -- четыре входа
        sel     : in  std_logic_vector(1 downto 0);     -- адрес входа
        y       : out std_logic
    );
end entity mux4;

architecture rtl of mux4 is
begin
    -- выбор по значению адреса; вариант others обязателен,
    -- так как std_logic имеет девять состояний, а не два
    with sel select
        y <= d(0) when "00",
             d(1) when "01",
             d(2) when "10",
             d(3) when "11",
             '0'  when others;
end architecture rtl;
