VHDL Programming

(C. Jardin) #1

226 Chapter Eight


This example shows how to read a single integer value from a line,
square the value, and write the squared value to another file. It illustrates
how TextIO can be used to read values from files and write values to files.
The process statement is executed whenever signal gohas an event
occur. The process then loops until an end-of-file condition occurs on the
input file infile. The READLINEstatement reads a line from the file and
places the line in variable my_line. The next executable line contains a
READprocedure call that reads a single integer value from my_lineinto
variable int_val. Procedure READis an overloaded procedure that reads
different type values from the line, depending on the type of the argument
passed to it.
After the value from the file has been read into variable int_val, the
variable is squared, and the squared value is written to another variable
of type line, called out_line. Procedure WRITEis also an overloaded
procedure that writes a number of different value types, depending on the
type of the argument passed to it.
The last TextIO procedure call made is the WRITELINEprocedure call. This
procedure writes out the line variable out_lineto the output file outfile.
If the following input file is used as input to this architecture, the second
file shown reflects the output generated:

10

20

50

16#A <— hex input
1_2_3 <— underscores ignored
87 52 <— second argument ignored

The output from the input file would look like this:

100

400

2500

100

15129

7569

The first value in the input file is 10. It is squared to result in 100 and
written to the output file. The same is true for the values 20 and 50. The
next value in the file is specified in hexadecimal notation. A hexadecimal
A value is 10 base ten, which squared results in 100.
The next example in the file shows a number with embedded underscore
characters. The underscores are used to separate fields of a number and are
ignored in the value of the number. The number 1_2_3 is the same as 123.
Free download pdf