Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss
Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

file io prob in vhdl

648 views
Skip to first unread message

zinga...@yahoo.com

unread,
Jan 25, 2005, 6:27:52 AM1/25/05
to
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

Jonathan Bromley

unread,
Jan 25, 2005, 9:51:32 AM1/25/05
to
On 25 Jan 2005 03:27:52 -0800, zinga...@yahoo.com wrote:

>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:jonathan...@doulos.com
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.

VHDL_lover

unread,
Jan 25, 2005, 10:08:06 PM1/25/05
to
Can you send me your code as I think there is no problem reading a text
file.

zinga...@yahoo.com

unread,
Jan 26, 2005, 12:46:48 AM1/26/05
to
thanks jonathan, yeah I can do that with textio but was trying other
approaches.


-Neo

Jonathan Bromley

unread,
Jan 26, 2005, 4:52:38 AM1/26/05
to
On 25 Jan 2005 21:46:48 -0800, zinga...@yahoo.com wrote:

>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.

Mike Treseler

unread,
Jan 26, 2005, 11:10:34 AM1/26/05
to
zinga...@yahoo.com wrote:

> 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.

Write the file before you read it.
Here is an example with characters.
http://groups-beta.google.com/groups?q=vhdl+char_range

-- Mike Treseler

zinga...@yahoo.com

unread,
Jan 27, 2005, 4:02:31 AM1/27/05
to
yep that works, but not preferable as you pointed out.
thanks guys.

-neo

Brian Drummond

unread,
Jan 27, 2005, 6:16:59 AM1/27/05
to
On 25 Jan 2005 03:27:52 -0800, zinga...@yahoo.com wrote:

>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

Charles Bailey

unread,
Feb 11, 2005, 10:54:14 PM2/11/05
to

"Jonathan Bromley" <jonathan...@doulos.com> wrote in message
news:5lpev0969vmhmvl1v...@4ax.com...

> 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


0 new messages