file io prob in vhdl

Z

zingafriend

The piece of code goes like this:
process
variable m,n: integer:=0;
type integer_file is file of integer;
file intfile: integer_file open read_mode is "integers.txt";
begin
while not(endfile(intfile)) loop
read(intfile,m);
read(intfile,n);
----
----

end process;

The values in the file integers.txt are like 3,4,10,12 etc seperated by
space. But when it reads the values m & n, its getting it all wrong,
the values being very high like 805965104,221252109,168636426,... etc.
I am bugged as to what is happening.

-neo
 
J

Jonathan Bromley

The piece of code goes like this:
process
variable m,n: integer:=0;
type integer_file is file of integer;
file intfile: integer_file open read_mode is "integers.txt";
begin
while not(endfile(intfile)) loop
read(intfile,m);
read(intfile,n); [..]
The values in the file integers.txt are like 3,4,10,12 etc seperated by
space. But when it reads the values m & n, its getting it all wrong,
the values being very high like 805965104,221252109,168636426,... etc.

To read from a "file of integer" using read(), you must have written
the file using VHDL write()...

unless you know the internal binary representation of integer
that's used by your simulator vendor...

so don't do that. Use std.textio instead. Plenty of examples
around about how to do that.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:[email protected]
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
Z

zingafriend

thanks jonathan, yeah I can do that with textio but was trying other
approaches.


-Neo
 
J

Jonathan Bromley

thanks jonathan, yeah I can do that with textio but
was trying other approaches.

OK.

I *guess* that most simulators will treat "file of integer"
as a straight binary file, with each integer packed as 4
bytes. Try *writing* a "file of integer" from VHDL, with
a few known integer values, and look at the resulting file
with a text editor that understands how to do binary/hex
byte-by-byte editing, or with "od" in *nix.

The biggest problems (i.e. differences among simulators and
operating systems) are likely to relate to endianness
and end-of-file detection.

You can usually do a fairly good job of reading/writing
binary files from VHDL by treating them as "file of character",
but once again it's not guaranteed to be portable. Plain-text
is the right way to do it in VHDL. It's easy to write external
scripts or C programs to convert between VHDL-friendly text and
software-friendly binary representations.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:[email protected]
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
B

Brian Drummond

The piece of code goes like this: [...]

The values in the file integers.txt are like 3,4,10,12 etc seperated by
space. But when it reads the values m & n, its getting it all wrong,
the values being very high like 805965104,221252109,168636426,... etc.
I am bugged as to what is happening.

In hex, these three numbers are X"300A0D30", X"0D300A0D", X"0A0D300A".

Given a table of ASCII values, it shouldn't be difficult to figure out
what's going on.

Try reading this file using std.textio.

- Brian
 
C

Charles Bailey

Jonathan Bromley said:
You can usually do a fairly good job of reading/writing
binary files from VHDL by treating them as "file of character",
but once again it's not guaranteed to be portable.

I've had good results reading and writing binary files using a file type
of character. It works the same on both an IBM PC (byte little-endian
architecture) and an IBM RS6000 (byte big-endian architecture). Reading
or writing one character at a time gets around the little/big-endian
confusion of integer representation.

Charles Bailey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
Martindap

Latest Threads

Top