I am trying to read in a hex file that is n lines long, with each line consisting of a 32-bit hex value. I then need to take the 32-bit hex values and turn them into 8-bit bytes to be used in a memory model.
I am able to open the file and loop through it to extract each value in a line and see that I am reading each line correctly with this loop:
fd = $fopen("test.dat", "r");
if(fd)
begin
$display("Reading file %0d", fd);
for(int i=0; i<num_lines; i++)
begin
$fscanf(fd, "%h", line[i]);
$display("line: %h", line[i]);
end
end
I get a console output when running my test bench of
line: 00000000
line: 00000001
line: 00000002
line: 00000003
line: 00000004
line: 00000005
line: 00000006
line: 00000007
line: 00000008
line: 00000009
line: 0000000a
line: 0000000b
line: 0000000c
line: 0000000d
line: 0000000e
line: 0000000f
line: 00000010
line: 00000011
line: ffffffff
which is what I expect.
I am having trouble splitting these values into four 8-bit bytes each.
I want the first line to be split into 00 00 00 00
the second to be 00 00 00 01
and so on. I need to save the bytes in its own variable to be looped through and inserted into a memory model for test benching.