|
library IEEE; |
|
use IEEE.std_logic_1164.all; |
|
use IEEE.numeric_std.all; |
|
|
|
entity testbench is |
|
end entity; |
|
|
|
architecture tb_behavior of testbench is |
|
|
|
-- component declarations |
|
component alu is |
|
port( |
|
-- inputs: |
|
R, S : in unsigned(15 downto 0); -- operands |
|
I : in std_logic_vector(5 downto 3); -- which operation should be executed |
|
cin, clk, ce : in std_logic; -- carry in, clock, CE-input (whether component should be active or not) |
|
|
|
-- outputs: |
|
cout, sign, zero: out std_logic; -- carry, sign, zero flag |
|
F : out unsigned(15 downto 0) -- result |
|
); |
|
end component; |
|
|
|
-- input signals |
|
signal R : unsigned(15 downto 0) := "0101000011010001"; |
|
signal S : unsigned(15 downto 0) := "0100001011011111"; |
|
signal cin, clk : std_logic := '1'; |
|
signal ce : std_logic := '0'; |
|
signal I : std_logic_vector(5 downto 3) := "000"; |
|
signal eff : std_logic := '1'; |
|
|
|
-- output signals |
|
signal cout, sign, zero : std_logic; |
|
signal F : unsigned(15 downto 0); |
|
|
|
begin |
|
|
|
-- concurrent statements |
|
|
|
clk <= not clk after 10 ns; |
|
-- clock speed: 50 MHz |
|
|
|
cin <= not cin after 240 ns; |
|
-- one effective clock cycle = 160 ns |
|
-- => 3 effective clock cycles = 480 ns |
|
-- => change every 480 second, so that every calculation gets tested with and without carry-in |
|
|
|
eff <= not eff after 40 ns; |
|
-- 4 base clock cycles = 1 effective clock cycle |
|
|
|
-- processes |
|
|
|
process(eff) is |
|
begin |
|
if rising_edge(eff) then |
|
|
|
R <= R + 1; |
|
S <= S + 3; |
|
|
|
CE <= '0', '1' after 40 ns, '0' after 60 ns; |
|
-- calculation happening in every third base clock cycle |
|
|
|
case I is |
|
-- so that every operation is used equally often, just switching to the "next one" |
|
when "000" => I <= "001"; |
|
when "001" => I <= "010"; |
|
when "010" => I <= "011"; |
|
when "011" => I <= "100"; |
|
when "100" => I <= "101"; |
|
when "101" => I <= "110"; |
|
when "110" => I <= "111"; |
|
when others => I <= "000"; |
|
end case; |
|
end if; |
|
end process; |
|
|
|
-- instances |
|
|
|
test_alu1 : alu |
|
port map ( |
|
-- inputs: |
|
R => R, |
|
S => S, |
|
I => I, |
|
ce => ce, |
|
cin => cin, |
|
clk => clk, |
|
|
|
-- outputs: |
|
cout => cout, |
|
sign => sign, |
|
zero => zero, |
|
F => F |
|
); |
|
end architecture; |