Advertisement
lasthunter657

Untitled

Dec 21st, 2021
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use STD.textio.all;
  5. use ieee.std_logic_textio.all;
  6.  
  7. entity example_file_io_tb is
  8.  
  9. end example_file_io_tb;
  10.  
  11.  
  12. architecture behave of example_file_io_tb is
  13.  
  14. -----------------------------------------------------------------------------
  15. -- Declare the Component Under Test
  16. -----------------------------------------------------------------------------
  17. component ripple_carry_adder is
  18. generic (
  19. g_WIDTH : natural);
  20. port (
  21. i_add_term1 : in std_logic_vector(g_WIDTH-1 downto 0);
  22. i_add_term2 : in std_logic_vector(g_WIDTH-1 downto 0);
  23. o_result : out std_logic_vector(g_WIDTH downto 0)
  24. );
  25. end component ;
  26.  
  27. -----------------------------------------------------------------------------
  28. -- Testbench Internal Signals
  29. -----------------------------------------------------------------------------
  30. file file_VECTORS : text;
  31. file file_RESULTS : text;
  32. constant c_width : natural := 4 ;
  33. signal r_ADD_TERM1 : std_logic_vector(c_width-1 downto 0) := (others => '0');
  34. signal r_ADD_TERM2 : std_logic_vector(c_width-1 downto 0) := (others => '0');
  35. signal w_SUM : std_logic_vector(c_width downto 0);
  36.  
  37. begin
  38.  
  39. -----------------------------------------------------------------------------
  40. -- Instantiate and Map UUT
  41. -----------------------------------------------------------------------------
  42. MODULE_RIPPLE_CARRY_ADDER_INST : ripple_carry_adder
  43. generic map (
  44. g_WIDTH => c_WIDTH)
  45. port map (
  46. i_add_term1 => r_ADD_TERM1,
  47. i_add_term2 => r_ADD_TERM2,
  48. o_result => w_SUM
  49. );
  50.  
  51.  
  52. ---------------------------------------------------------------------------
  53. -- This procedure reads the file input_vectors.txt which is located in the
  54. -- simulation project area.
  55. -- It will read the data in and send it to the ripple-adder component
  56. -- to perform the operations. The result is written to the
  57. -- output_results.txt file, located in the same directory.
  58. ---------------------------------------------------------------------------
  59. process
  60. variable v_ILINE : line;
  61. variable v_OLINE : line;
  62. variable v_ADD_TERM1 : std_logic_vector(c_WIDTH-1 downto 0);
  63. variable v_ADD_TERM2 : std_logic_vector(c_WIDTH-1 downto 0);
  64. variable v_SPACE : character;
  65.  
  66. begin
  67.  
  68. file_open(file_VECTORS, "D:\UNI\ITCE211\Codes\textio2\input_vectors.txt", read_mode);
  69. file_open(file_RESULTS, "D:\UNI\ITCE211\Codes\textio2\output_results.txt", write_mode);
  70.  
  71. while not endfile(file_VECTORS) loop
  72. readline(file_VECTORS, v_ILINE);
  73. read(v_ILINE, v_ADD_TERM1);
  74. read(v_ILINE, v_SPACE); -- read in the space character
  75. read(v_ILINE, v_ADD_TERM2);
  76.  
  77. -- Pass the variable to a signal to allow the ripple-carry to use it
  78. r_ADD_TERM1 <= v_ADD_TERM1;
  79. r_ADD_TERM2 <= v_ADD_TERM2;
  80.  
  81. wait for 100 ps;
  82.  
  83. write(v_OLINE, w_SUM, right, c_WIDTH);
  84. writeline(file_RESULTS, v_OLINE);
  85. end loop;
  86.  
  87. file_close(file_VECTORS);
  88. file_close(file_RESULTS);
  89.  
  90. wait;
  91. end process;
  92.  
  93. end behave;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement