Advertisement
lasthunter657

Untitled

Dec 21st, 2021
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 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 Fulladder_generic is
  18. GENERIC (
  19. data_width : INTEGER := 4);
  20. PORT (
  21. a : IN STD_LOGIC_VECTOR (data_width - 1 DOWNTO 0);
  22. b : IN STD_LOGIC_VECTOR (data_width - 1 DOWNTO 0);
  23. cin : IN STD_LOGIC :='0';
  24. s : OUT STD_LOGIC_VECTOR (data_width - 1 DOWNTO 0);
  25. cout : OUT STD_LOGIC);
  26. END COMPONENT ;
  27. -----------------------------------------------------------------------------
  28. -- Testbench Internal Signals
  29. -----------------------------------------------------------------------------
  30. file file_VECTORS : text;
  31. file file_RESULTS : text;
  32.  
  33. constant c_WIDTH : natural := 4;
  34.  
  35. signal r_ADD_TERM1 : std_logic_vector(c_WIDTH-1 downto 0) := (others => '0');
  36. signal r_ADD_TERM2 : std_logic_vector(c_WIDTH-1 downto 0) := (others => '0');
  37. signal w_SUM : std_logic_vector(c_WIDTH-1 downto 0);
  38.  
  39. begin
  40.  
  41. -----------------------------------------------------------------------------
  42. -- Instantiate and Map UUT
  43. -----------------------------------------------------------------------------
  44. fulladder_inst : Fulladder_generic
  45. generic map (
  46. data_width => c_WIDTH)
  47. port map (
  48. a => r_ADD_TERM1,
  49. b => r_ADD_TERM2,
  50. s => w_SUM
  51. );
  52.  
  53.  
  54. ---------------------------------------------------------------------------
  55. -- This procedure reads the file input_vectors.txt which is located in the
  56. -- simulation project area.
  57. -- It will read the data in and send it to the ripple-adder component
  58. -- to perform the operations. The result is written to the
  59. -- output_results.txt file, located in the same directory.
  60. ---------------------------------------------------------------------------
  61. process
  62. variable v_ILINE : line;
  63. variable v_OLINE : line;
  64. variable v_ADD_TERM1 : std_logic_vector(c_WIDTH-1 downto 0);
  65. variable v_ADD_TERM2 : std_logic_vector(c_WIDTH-1 downto 0);
  66. variable v_SPACE : character;
  67.  
  68. begin
  69.  
  70. file_open(file_VECTORS, "D:\UNI\ITCE211\Codes\textio3\input_vectors.txt", read_mode);
  71. file_open(file_RESULTS, "D:\UNI\ITCE211\Codes\textio3\output_results.txt", write_mode);
  72.  
  73. while not endfile(file_VECTORS) loop
  74. readline(file_VECTORS, v_ILINE);
  75. read(v_ILINE, v_ADD_TERM1);
  76. read(v_ILINE, v_SPACE); -- read in the space character
  77. read(v_ILINE, v_ADD_TERM2);
  78.  
  79. -- Pass the variable to a signal to allow the ripple-carry to use it
  80. r_ADD_TERM1 <= v_ADD_TERM1;
  81. r_ADD_TERM2 <= v_ADD_TERM2;
  82.  
  83. wait for 60 ns;
  84.  
  85. write(v_OLINE, w_SUM, right, c_WIDTH);
  86. writeline(file_RESULTS, v_OLINE);
  87. end loop;
  88.  
  89. file_close(file_VECTORS);
  90. file_close(file_RESULTS);
  91.  
  92. wait;
  93. end process;
  94.  
  95. end behave;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement