Advertisement
cofyye

MUX 4 TO 1

Apr 7th, 2023
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.24 KB | Source Code | 0 0
  1. -- design.vhd
  2.  
  3. library IEEE;
  4. use IEEE.std_logic_1164.all;
  5.  
  6. entity mux_4to1 is
  7.     port(A : in bit_vector(3 downto 0);
  8.        Sel : in bit_vector(1 downto 0);
  9.          F : out bit);
  10. end entity mux_4to1;
  11.  
  12. architecture mux_4to1_arch of mux_4to1 is
  13. begin
  14.     process(A, Sel)
  15.     begin
  16.         if(Sel = "00") then
  17.             F <= A(0);
  18.         elsif(Sel = "01") then
  19.             F <= A(1);
  20.         elsif(Sel = "10") then
  21.             F <= A(2);
  22.         elsif(Sel = "11") then
  23.             F <= A(3);
  24.         else
  25.             F <= '0';
  26.         end if;
  27.     end process;
  28. end architecture mux_4to1_arch;
  29.        
  30.  
  31. -- testbench.vhd
  32.  
  33. library IEEE;
  34. use IEEE.std_logic_1164.all;
  35.  
  36. entity mux_4to1_tb is
  37. end entity mux_4to1_tb;
  38.  
  39. architecture mux_4to1_tb_arch of mux_4to1_tb is
  40.     signal A : bit_vector(3 downto 0);
  41.     signal Sel : bit_vector(1 downto 0);
  42.     signal F : bit;
  43. begin
  44.     DUT1 : entity work.mux_4to1(mux_4to1_arch)
  45.            port map(A, Sel, F);
  46.     STIMULUS : process
  47.     begin
  48.          A <= "0101"; wait for 10ns;
  49.          Sel <= "00"; wait for 10ns;
  50.          Sel <= "01"; wait for 10ns;
  51.          Sel <= "10"; wait for 10ns;
  52.          Sel <= "11"; wait for 10ns;
  53.          Sel <= "XX"; wait for 10ns;
  54.     end process STIMULUS;
  55. end architecture mux_4to1_tb_arch;
Tags: VHDL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement