如何在VHDL中从文本文件中读取32位std_逻辑_矢量数据

如何在VHDL中从文本文件中读取32位std_逻辑_矢量数据,vhdl,Vhdl,我想从文本文件中读取32位带符号的数字,并将其存储在变量中。我有用于整数读取的程序,但它不适用于std_逻辑_向量类型。使用VHDL-2008,可以按如下方式执行: library ieee; use ieee.std_logic_1164.all; use std.textio.all; architecture syn of tb is begin process is file txt_file : text; variable line_v : line;

我想从文本文件中读取32位带符号的数字,并将其存储在变量中。我有用于整数读取的程序,但它不适用于std_逻辑_向量类型。

使用VHDL-2008,可以按如下方式执行:

library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;

architecture syn of tb is
begin
  process is
    file txt_file   : text;
    variable line_v : line;
    variable slv_v  : std_logic_vector(31 downto 0);
    variable good_v : boolean;
  begin
    -- Write text file with std_logic_vector
    file_open(txt_file, "test.txt", write_mode);
    slv_v := X"1234" & "XXXXXXXX" & "ZZZZZZZZ" ;
    write(line_v, slv_v);
    writeline(txt_file, line_v);
    file_close(txt_file);
    -- Read text file with std_logic_vector
    file_open(txt_file, "test.txt", read_mode);
    readline(txt_file, line_v);
    report "line_v: " & line_v.all;
    read(line_v, slv_v, good_v);
    file_close(txt_file);
    -- Done
    wait;
  end process;
end architecture;
然后,“test.txt”文本文件包含:

000100100100010100xxxxxxxzzzzzzzz

对于VHDL-2002,在
写入
/
读取
过程中不支持
标准逻辑向量
,但Synopsys软件包
ieee.std逻辑文本可用于为过程提供:

use ieee.std_logic_textio.all;