1 | library std;
|
2 | use std.textio.all; --include package textio.vhd
|
3 |
|
4 |
|
5 | --entity declaration
|
6 | entity filehandle is
|
7 | end filehandle;
|
8 |
|
9 |
|
10 | --architecture definition
|
11 | architecture Behavioral of filehandle is
|
12 | --period of clock,bit for indicating end of file.
|
13 | signal clock,endoffile : bit := '0';
|
14 | --data read from the file.
|
15 | signal dataread : real;
|
16 | --data to be saved into the output file.
|
17 | signal datatosave : real;
|
18 | --line number of the file read or written.
|
19 | signal linenumber : integer:=1;
|
20 |
|
21 |
|
22 | begin
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | clock <= not (clock) after 1 ns; --clock with time period 2 ns
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | --read process
|
33 | reading :
|
34 | process
|
35 | file infile : text is in "bit8.txt"; --declare input file
|
36 | variable inline : line; --line number declaration
|
37 | variable dataread1 : real;
|
38 | begin
|
39 | wait until clock = '1' and clock'event;
|
40 | if (not endfile(infile)) then --checking the "END OF FILE" is not reached.
|
41 | readline(infile, inline); --reading a line from the file.
|
42 | --reading the data from the line and putting it in a real type variable.
|
43 | read(inline, dataread1);
|
44 | dataread <=dataread1; --put the value available in variable in a signal.
|
45 | else
|
46 | endoffile <='1'; --set signal to tell end of file read file is reached.
|
47 | end if;
|
48 |
|
49 |
|
50 | end process reading;
|
51 |
|
52 |
|
53 | --write process
|
54 | writing :
|
55 | process
|
56 | file outfile : text is out "bit8_inv.txt"; --declare output file
|
57 | variable outline : line; --line number declaration
|
58 | begin
|
59 | wait until clock = '0' and clock'event;
|
60 | if(endoffile='0') then --if the file end is not reached.
|
61 | --write(linenumber,value(real type),justified(side),field(width),digits(natural) );
|
62 | write(outline, dataread, right, 16, 12);
|
63 | -- write line to external file.
|
64 | writeline(outfile, outline);
|
65 | linenumber <= linenumber + 1;
|
66 | else
|
67 | null;
|
68 | end if;
|
69 |
|
70 |
|
71 | end process writing;
|
72 | end behavioral;
|