File output - binary value zero.

H

Harrkev

Guest
Hi. I am working on verilog whose purpose is to handle graphical
data. I am trying to have my verilog testbench read data from the
RAM, and actually generate a .BMP file.

Here is the problem. I can output hex values like this:

reg [7:0] data;
$fwrite(file,"%s",data);

This woks fine --- unless the data is happens to be 8'h00 (which
happens a LOT in the header of a .bmp file), and then the data that
gets written to disk is 8'h20 (ascii space).

I even tried this:

if (data == 8'h0) $fwrite(file,"\000");
else $fwrite(file,"%s",data);

And the zeroed data does not even get written. I am using NC-Verilog
06.20-s004.

My backup plan is to dump the data in ascii hex, and have perl do all
of the heavy lifting. Not elegant, but fuctional. I would rather not
have to do this. Any ideas on how I can get Verilog to do what I
want?

Thanks.
 
Harrkev wrote:
Hi. I am working on verilog whose purpose is to handle graphical
data. I am trying to have my verilog testbench read data from the
RAM, and actually generate a .BMP file.

Here is the problem. I can output hex values like this:

reg [7:0] data;
$fwrite(file,"%s",data);

This woks fine --- unless the data is happens to be 8'h00 (which
happens a LOT in the header of a .bmp file), and then the data that
gets written to disk is 8'h20 (ascii space).

I even tried this:

if (data == 8'h0) $fwrite(file,"\000");
else $fwrite(file,"%s",data);

And the zeroed data does not even get written. I am using NC-Verilog
06.20-s004.

My backup plan is to dump the data in ascii hex, and have perl do all
of the heavy lifting. Not elegant, but fuctional. I would rather not
have to do this. Any ideas on how I can get Verilog to do what I
want?

Thanks.
It should work the same way as %s, but maybe you could try the
single-character %c operator:

$fwrite(file,"%c",data);

-Kevin
 
On May 30, 9:17 am, Harrkev <kevin.harrel...@gmail.com> wrote:
Hi. I am working on verilog whose purpose is to handle graphical
data. I am trying to have my verilog testbench read data from the
RAM, and actually generate a .BMP file.

Here is the problem. I can output hex values like this:

reg [7:0] data;
$fwrite(file,"%s",data);

This woks fine --- unless the data is happens to be 8'h00 (which
happens a LOT in the header of a .bmp file), and then the data that
gets written to disk is 8'h20 (ascii space).

I even tried this:

if (data == 8'h0) $fwrite(file,"\000");
else $fwrite(file,"%s",data);

And the zeroed data does not even get written. I am using NC-Verilog
06.20-s004.

My backup plan is to dump the data in ascii hex, and have perl do all
of the heavy lifting. Not elegant, but fuctional. I would rather not
have to do this. Any ideas on how I can get Verilog to do what I
want?

Thanks.
I would be tempted to write my own "fwrite_bmp" PLI.

<http://www.angelfire.com/ca/verilog/chap1.html>

G.
 
Using "%c" worked like a champ. Thanks.

On May 30, 10:46 am, Kevin Neilson
<kevin_neil...@removethiscomcast.net> wrote:
It should work the same way as %s, but maybe you could try the
single-character %c operator:

$fwrite(file,"%c",data);

-Kevin
 

Welcome to EDABoard.com

Sponsor

Back
Top