Verilog file operations

Sep 07, 2012 5 Replies

Hi



I want to write some data to a file using Verilog. This file will be a JPEG file so the data in the file needs to be the actual data I write. I have tried using $fwrite but the data ends up as ASCII when I look at it in a hex editor. So if I write 0xFF it ends up as 66 66 in the file. Can anyone tell me how to do this?


Thanks



Jon



--------------------------------------- Posted through

formatting link


Try google.. here is what I found (last post using character binary mode)

formatting link

Just a guess: maybe there is hwrite()?

$fwrite uses the same format string as $write, so it's important to use the correct format. Obviously if you do something like:

reg [7:0] foo = 8'hFF; $fwrite ("%x", foo);

You'll get hex characters in the file. I haven't tried this but if you use a string or character type instead you should just get the binary data in the file. Note that this only works for multiples of 8 bits:

reg [7:0] foo = 8'hFF; $fwrite ("%c", foo);

reg [23:0] bar = 24'h123456; $fwrite ("%s", bar);

HTH, Gabor

integer fd;

initial begin fd = $fopen("data.out","wb"); $fwrite(fd,"%u",32'h61_62_00_63); $fclose(fd); end

//Petter

.sig removed by request.

After some experimenting and searching the web, the following works.

file_out = $fopen("test.jpg", "wb"); $fwriteb(file_out, "%c", ram_byte);

Thanks

Jon

--------------------------------------- Posted through

formatting link

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required