'I get a warning about $readmemh: Too many words in the file

Here is how I define the rom module

module rom(
    input   wire    [31:0]  inst_addr_i,
    output  reg     [31:0]  inst_o
);

    reg [31:0]  rom_mem[0:100];

    always@(*) begin
        inst_o = rom_mem[inst_addr_i>>2];
    end

endmodule

Here is the $readmem in tb.v

initial begin
        $readmemh("inst.data",tb.rv_soc_ins.rom_ins.rom_mem);
end

And the inst.data file is like this, which has 354 rows.

00000d13
00000d93
00000093
00000113
00208f33
00000e93
00200193

This is what I get when executing the vpp script:

$ vvp a.out 
WARNING: tb.v:23: $readmemh(inst.data): Too many words in the file for the requested range [0:100].
VCD info: dumpfile gtk.vcd opened for output.

Although in rom.v, I have set the rom large enough.



Solution 1:[1]

The warning is saying that your file (with 354 rows) is longer than your array (with 101 elements).

The message about VCD is unconnected: it is simply the next message telling you that the file "gtk.vcd" has been opened.

Solution 2:[2]

reg [31:0]  rom_mem[0:100];

The above declaration means that you have a memory with 101 32-bit words.

  • [0:100] means there are 101 locations (addresses) in the memory.
  • [31:0] means the memory location (data) is 32 bits wide.

Your inst.data file has 354 rows (or lines) in the file. Each row you showed has one 32-bit data word. Assuming you have one word on each row for the remainder of the file, then you have 354 words in the file.

The warning message tells you that your rom is not large enough to fit all the data words in the file.

I added some comments to the data file to illustrate what Verilog does with the data:

00000d13 // row 1 data loaded into rom_mem[0]
00000d93 // row 2 data loaded into rom_mem[1]
00000093
00000113
...
11111111 // row 100 data loaded into rom_mem[99]
22222222 // row 101 data loaded into rom_mem[100]
33333333 // row 102 data is discarded
...
ffffffff // row 354 data is discarded

As you can see, only the first 101 data words are loaded into the memory. The remaining data words are not used.

If you really want your memory to be 32x101 and you want to get rid of the warning, then you can delete the lines of the file starting at line 102, or you could specify start and end addresses:

    $readmemh("inst.data", tb.rv_soc_ins.rom_ins.rom_mem, 0, 101);

If you really want your memory to be 32x354, then you need to change the rom module:

reg [31:0]  rom_mem[0:353];

Refer to IEEE Std 1800-2017, section 21.4 Loading memory array data from a file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matthew Taylor
Solution 2