Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.15 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    07:58:40 10/18/2017
  6. -- Design Name:
  7. -- Module Name:    ALU - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_ARITH.ALL;
  23. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  24.  
  25. -- Uncomment the following library declaration if using
  26. -- arithmetic functions with Signed or Unsigned values
  27. --use IEEE.NUMERIC_STD.ALL;
  28.  
  29. -- Uncomment the following library declaration if instantiating
  30. -- any Xilinx primitives in this code.
  31. --library UNISIM;
  32. --use UNISIM.VComponents.all;
  33.  
  34. entity ALU is
  35.     Port ( A : in  STD_LOGIC_VECTOR (3 downto 0);
  36.            B : in  STD_LOGIC_VECTOR (3 downto 0);
  37.            f1 : in  STD_LOGIC;
  38.            f0 : in  STD_LOGIC;
  39.            Y : out  STD_LOGIC_VECTOR (4 downto 0));
  40. end ALU;
  41.  
  42. architecture Behavioral of ALU is
  43.  
  44. begin
  45.  
  46. process(f0,f1)
  47.   begin
  48.   if f0='0' and f1='0' then
  49.       Y<=A+B;
  50.     elsif (f0='1' and f1='0') then
  51.       Y<=A-B;
  52.    elsif (f0='0' and f1='1') then
  53.       Y<=A and B;  
  54.    elsif (f0='1' and f1='1') then
  55.       Y<=A or B;       
  56.     end if;
  57.    end process;
  58.  
  59.  
  60. end Behavioral;
  61.  
  62. --
  63. LIBRARY ieee;
  64. USE ieee.std_logic_1164.ALL;
  65. use IEEE.STD_LOGIC_ARITH.ALL;
  66. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  67.  
  68. -- Uncomment the following library declaration if using
  69. -- arithmetic functions with Signed or Unsigned values
  70. --USE ieee.numeric_std.ALL;
  71.  
  72. ENTITY ALU_test IS
  73. END ALU_test;
  74.  
  75. ARCHITECTURE behavior OF ALU_test IS
  76.  
  77.     -- Component Declaration for the Unit Under Test (UUT)
  78.  
  79.     COMPONENT ALU
  80.     PORT(
  81.          A : IN  std_logic_vector(3 downto 0);
  82.          B : IN  std_logic_vector(3 downto 0);
  83.          f1 : IN  std_logic;
  84.          f0 : IN  std_logic;
  85.          Y : OUT  std_logic_vector(4 downto 0)
  86.         );
  87.     END COMPONENT;
  88.    
  89.  
  90.    --Inputs
  91.    signal A : std_logic_vector(3 downto 0) := (others => '0');
  92.    signal B : std_logic_vector(3 downto 0) := (others => '0');
  93.    signal f1 : std_logic := '0';
  94.    signal f0 : std_logic := '0';
  95.  
  96.     --Outputs
  97.    signal Y : std_logic_vector(4 downto 0);
  98.    -- No clocks detected in port list. Replace <clock> below with
  99.    -- appropriate port name
  100.     BEGIN
  101.    
  102.  uut: ALU PORT MAP (
  103.           A => A,
  104.           B => B,
  105.           f1 => f1,
  106.           f0 => f0,
  107.           Y => Y
  108.         );
  109.          
  110.   -- constant <clock>_period : time := 10 ns;
  111.        -- Clock process definitions
  112.  
  113.     --  <clock>_process :process
  114. --   begin
  115.     --  <clock> <= '0';
  116.         --wait for <clock>_period/2;
  117.         --<clock> <= '1';
  118.         --wait for <clock>_period/2;
  119.    --end process;
  120.    
  121.    
  122.      -- Stimulus process
  123.    stim_proc: process
  124.    begin       
  125.       -- hold reset state for 100 ns.
  126.       wait for 100 ms; 
  127.      A<="0001";
  128.       B<="1100";
  129.       f1<='0';
  130.       f0<='0';
  131.      
  132.      -- wait for <clock>_period*10;
  133.      
  134.       -- insert stimulus here
  135.  
  136.       wait;
  137.    end process;
  138.  
  139.  
  140.  
  141. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement