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