read hex data from a file

V

vinoth

Guest
Hi..

how do i read hex data from a file..say for example the file
contains the following data...
e46e16c5891b3c295ed5f6c1db0087c3320
I want to read 32 bits at a time...
can anyone give me a suggestion..
 
On 29 Mar, 11:34, "vinoth" <jesuraj.vin...@gmail.com> wrote:
Hi..

how do i read hex data from a file..say for example the file
contains the following data...
e46e16c5891b3c295ed5f6c1db0087c3320
I want to read 32 bits at a time...
can anyone give me a suggestion..
Is the file you are reading binary, or is it a text file contain the
hex values?
Does the format of the data in the file have to be exactly as you have
defined, or can it be broken up with whitespace (for example)?

e46e16c5
891b3c29
5ed5f6c1
etc

If it's a text file and you can control the format, then look up
$fscanf (Verilog 2001 only - much the same as the C function of the
same name) or $readmemh.
If it's a binary file then you have to use $fread (Verilog 2001 only).
 
The best way to read this as a file would be to define the bit width
of the pattern you are trying to read:
For example if your hex data is 32 bits wide, your file should store
values as follows
12345678
23456789
abcdef12, etc. Save this file as a "<filename>.dat" and store it in
the simulation working directory.
You will need to initialize your memory array in your code as follows
reg <bit width:0> memory <array size>;
Now, use the $readmemh command to read this file. Remember, the
different entries in your file should be separated by whitespace.
 

Welcome to EDABoard.com

Sponsor

Back
Top