Übungen der VHDL-Einführung
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_alu.vhd 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. library std;
  4. use std.env.all;
  5. use std.textio.all;
  6. library work;
  7. use work.test_utility.all;
  8. entity test_alu is
  9. generic( GUI_MODE : boolean; CHECK_RESULTS : boolean );
  10. end entity test_alu;
  11. architecture test of test_alu is
  12. signal clk : std_logic := '0';
  13. signal reset : std_logic := '1';
  14. signal operand_a : std_logic_vector(3 downto 0);
  15. signal operand_b : std_logic_vector(3 downto 0);
  16. signal opcode : std_logic_vector(1 downto 0);
  17. signal result_out : std_logic_vector(3 downto 0);
  18. signal flag_zero_out : std_logic;
  19. signal flag_or_out : std_logic;
  20. begin
  21. u_alu : entity work.SimpleALU
  22. port map (
  23. clk => clk,
  24. reset => reset,
  25. operand_a => operand_a,
  26. operand_b => operand_b,
  27. opcode => opcode,
  28. result_out => result_out,
  29. flag_zero_out => flag_zero_out,
  30. flag_or_out => flag_or_out
  31. );
  32. clk <= not clk after 10 ns;
  33. p_reset : process( clk )
  34. begin
  35. if falling_edge( clk ) then
  36. reset <= '0';
  37. end if;
  38. end process p_reset;
  39. p_run : process
  40. begin
  41. wait until falling_edge( reset );
  42. -- Addition
  43. write( output, "Test Addition ... " );
  44. opcode <= "00";
  45. operand_a <= x"a";
  46. operand_b <= x"5";
  47. wait until falling_edge( clk );
  48. wait until falling_edge( clk );
  49. assert_eq( result_out, x"f" );
  50. assert_eq( flag_zero_out, '0' );
  51. assert_eq( flag_or_out, '0' );
  52. write( output, "done" & LF );
  53. -- Subtraktion auf Null
  54. write( output, "Test Subtraktion ... " );
  55. opcode <= "01";
  56. operand_a <= x"a";
  57. operand_b <= x"a";
  58. wait until falling_edge( clk );
  59. wait until falling_edge( clk );
  60. assert_eq( result_out, x"0" );
  61. assert_eq( flag_zero_out, '1' );
  62. assert_eq( flag_or_out, '0' );
  63. write( output, "done" & LF );
  64. -- UND-Operation
  65. write( output, "Test UND-Operation ... " );
  66. opcode <= "10";
  67. operand_a <= x"a";
  68. operand_b <= x"3";
  69. wait until falling_edge( clk );
  70. wait until falling_edge( clk );
  71. assert_eq( result_out, x"2" );
  72. assert_eq( flag_zero_out, '0' );
  73. assert_eq( flag_or_out, '0' );
  74. write( output, "done" & LF );
  75. -- ODER-Operation
  76. write( output, "Test ODER-Operation ... " );
  77. opcode <= "11";
  78. operand_a <= x"a";
  79. operand_b <= x"3";
  80. wait until falling_edge( clk );
  81. wait until falling_edge( clk );
  82. assert_eq( result_out, x"b" );
  83. assert_eq( flag_zero_out, '0' );
  84. assert_eq( flag_or_out, '1' );
  85. write( output, "done" & LF );
  86. wait until falling_edge( clk );
  87. if ( GUI_MODE ) then
  88. std.env.stop;
  89. else
  90. std.env.finish;
  91. end if;
  92. end process p_run;
  93. end architecture test;