verilogiverilog

How to cancel address comment by $writememb?


When I use $writememb in Verilog to write contents in a memory to a text file, the result shows as below. But, I don't need the address comment. How can I cancel the comment when using $writememb? I use iverilog to compile my design.

// 0x00000000
00000000000000000000000000000001
00000000000000000000000000000010
00000000000000000000000000010100
00000000000000000000000000010000
00000000000000000000000000000100
00000000000000000000000000000011
11111111111111111111111111111111
11111111111111111111111111111100
00000000000000000000000000000100
00000000000000000000000000000000
00000000000000000000000000000001
11111111111111111111111111111000
11111111111111111111111111110000
00011111111111111111111111111111
00001111111111111111111111111111
11111111111111111111111111111110
// 0x00000010
11111111111111111111111111111100

I want a result like this:

00000000000000000000000000000001
00000000000000000000000000000010
00000000000000000000000000010100
00000000000000000000000000010000
00000000000000000000000000000100
00000000000000000000000000000011
11111111111111111111111111111111
11111111111111111111111111111100
00000000000000000000000000000100
00000000000000000000000000000000
00000000000000000000000000000001
11111111111111111111111111111000
11111111111111111111111111110000
00011111111111111111111111111111
00001111111111111111111111111111
11111111111111111111111111111110
11111111111111111111111111111100

Solution

  • According to IEEE Std 1800-2017, section 21.5 Writing memory array data to a file:

    The $writememb and $writememh system tasks can be used to dump memory array (see 7.4.4) contents to files that are readable by $readmemb and $readmemh , respectively.

    The file contents that you get with the address comply with the standard since the addresses are inside comments (//).

    This behavior seems to be unique to the iverilog simulator. I don't see comments when I use $writememb with other simulators.

    You can try to contact the iverilog developers to see if there is an option to disable comments.

    Or, you can try using other simulators.

    Or, you can write to an output file using $fopen and related functions.

    Or, you can post-process the output files to remove the comments using your favorite software language. If you are on a unix-like OS:

    grep -v // file.txt > new.txt