100 likes | 399 Views
Quad 2-to-1 and Quad 4-to-1 Multiplexers. Discussion D2.4 Example 7. Quad 2-to-1 Multiplexer. Quad 2-to-1 Multiplexer. y <= ~s*a + s*b;. may only AND bits of a STD_LOGIC_VECTOR of equal length. sel: STD_LOGIC_VECTOR(3 downto 0);. sel <= s & s & s & s;.
E N D
Quad 2-to-1 and Quad 4-to-1 Multiplexers Discussion D2.4 Example 7
Quad 2-to-1 Multiplexer y <= ~s*a + s*b; may only AND bits of a STD_LOGIC_VECTOR of equal length.
sel: STD_LOGIC_VECTOR(3 downto 0); sel <= s & s & s & s; y <= (not sel and a) or (sel and b);
-- Example 7a: Quad 2-to-1 MUX using logic equations library IEEE; use IEEE.STD_LOGIC_1164.all; entity mux24a is port( s : in STD_LOGIC; a : in STD_LOGIC_VECTOR(3 downto 0); b : in STD_LOGIC_VECTOR(3 downto 0); y : out STD_LOGIC_VECTOR(3 downto 0) ); end mux24a; architecture mux24a of mux24a is signal sel: STD_LOGIC_VECTOR(3 downto 0); begin sel <= s & s & s & s; y <= (not sel and a) or (sel and b); end mux24a;
-- Example 7b: Quad 2-to-1 MUX using if statement library IEEE; use IEEE.STD_LOGIC_1164.all; entity mux24b is port( s : in STD_LOGIC; a : in STD_LOGIC_VECTOR(3 downto 0); b : in STD_LOGIC_VECTOR(3 downto 0); y : out STD_LOGIC_VECTOR(3 downto 0) ); end mux24b; architecture mux24b of mux24b is begin process(a, b, s) begin if s = '0' then y <= a; else y <= b; end if; end process; end mux24b;
-- Example 7c: Quad 4-to-1 MUX using with..select..when library IEEE; use IEEE.STD_LOGIC_1164.all; entity mux44 is port( a : in STD_LOGIC_VECTOR(3 downto 0); b : in STD_LOGIC_VECTOR(3 downto 0); c : in STD_LOGIC_VECTOR(3 downto 0); d : in STD_LOGIC_VECTOR(3 downto 0); s : in STD_LOGIC_VECTOR(1 downto 0); y : out STD_LOGIC_VECTOR(3 downto 0) ); end mux44; architecture mux44 of mux44 is begin with s select y <= a when "00", b when "01", c when "10", d whenothers; end mux44; Note selected signal assignment statement