bnary files

P

PATRICE

Hello
I am trying to write a binary result file in vhdl.
I tried to write with type character, with narural ranged 0-255,
with array of 8bits but i never had the expected result.
(i expect to write 1 byte)

Can someone help me please

Thanks in advance
 
J

Jonathan Bromley

Hello
I am trying to write a binary result file in vhdl.
I tried to write with type character, with narural ranged 0-255,
with array of 8bits but i never had the expected result.
(i expect to write 1 byte)

In most simulators, "file of character" works OK. Precisely
what features of the result were unexpected?

The following process gives me a binary file containing
256 bytes, with values 0, 1, 2, ... 254, 255.

process
type charfile is file of character;
file f: charfile;
begin
file_open(f, "junk.bin", write_mode);
for i in 0 to 255 loop
write(f, character'val(i));
end loop;
file_close(f);
wait;
end process;

Strictly, this code is not portable across simulators and
operating systems. In practice, though, it works well.

Trying to write a file of "natural range 0 to 255" is
much less likely to work, because "natural range 0 to 255"
is a subtype of integer and therefore each object probably
occupies 32 bits. You can write files like this, with each
32-bit integer representing 4 bytes, but you are then at the
mercy of byte ordering conventions and suchlike.
--
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.
 

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

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,431
Latest member
ElyseG3173

Latest Threads

Top