write integer to file vhdl

2019-08-07 02:14发布

问题:

I would like to write an integer (variable num) on a file (write.txt). Here my code but obviously it does not work. Any suggestion?

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.MATH_REAL.ALL;
library std;
use std.textio.all;

entity file_handle is
end file_handle;

architecture Behavioral of file_handle is

begin

process

variable line_var : line;
file text_var : text;
variable num : integer := 40;

begin        
    file_open(text_var,"C:\Users\Tommy\Desktop\write.txt", write_mode);
    write(line_var, num);         -- write num into line_var
    writeline(text_var, line_var);   -- write line_var into the file
    file_close(text_var);
end process;

end Behavioral;

After running the synthesis, If I open write.txt file, I read b00000000000000000000000000101000. It seems an address or something else. I expected to read 40.

回答1:

Try write(line_var, integer'image(num)); instead. It will convert the variable num to a decimal string.



标签: vhdl fpga hdl