Verilog file operations

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

Reply to
maxascent
Loading thread data ...

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

formatting link

Reply to
Morten Leikvoll

Just a guess: maybe there is hwrite()?

Reply to
scrts

$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

Reply to
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.
Reply to
Petter Gustad

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

Reply to
maxascent

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.