C
Charles Bailey
Guest
I have a testbench in which I would like to monitor the sequence of
bytes on a data bus and write the bytes to a file in binary.
I open the output file with
integer wrdata, b1;
wrdata = $fopen("testdata.out", "wb");
and, on every clock cycle,
b1 = out_data[7:0];
$fwrite(wrdata,"%c", b1);
The problem is that, if out_data[7:0] == 8'h00, then
"$fwrite(wrdata,"%c", b1);" writes nothing. It seems that $fwrite sees
the all zeros byte as a string terminator (a la C null character) and
writes a zero-length string, that is, nothing.
I've also tried "$fwrite(wrdata,"%u", b1);", but that insists on writing
4 bytes to the file, regardless of how b1 is declared.
What I want to do is just write a straight binary file, without any
interpretation of the bytes and of any arbitrary length. I looked to
see if Verilog has something like $fputc, but apparently it doesn't. Is
there any way to do what I'm describing in Verilog?
Thanks,
Charles Bailey
bytes on a data bus and write the bytes to a file in binary.
I open the output file with
integer wrdata, b1;
wrdata = $fopen("testdata.out", "wb");
and, on every clock cycle,
b1 = out_data[7:0];
$fwrite(wrdata,"%c", b1);
The problem is that, if out_data[7:0] == 8'h00, then
"$fwrite(wrdata,"%c", b1);" writes nothing. It seems that $fwrite sees
the all zeros byte as a string terminator (a la C null character) and
writes a zero-length string, that is, nothing.
I've also tried "$fwrite(wrdata,"%u", b1);", but that insists on writing
4 bytes to the file, regardless of how b1 is declared.
What I want to do is just write a straight binary file, without any
interpretation of the bytes and of any arbitrary length. I looked to
see if Verilog has something like $fputc, but apparently it doesn't. Is
there any way to do what I'm describing in Verilog?
Thanks,
Charles Bailey