When I use your code to read the file, I get warning messages with 2 different simulators. In both cases, the simulator fails to read the file and load the data into the rom
variable. If I add the following code:
integer i;
initial for (i=0; i<=121; i=i+1) $displayb(rom[i]);
I see x
for all locations in rom
. You declared rom
as a reg
type, and reg
types default to x
.
The problem is that Line 1:
, Line 2:
, etc., are incorrect syntax. You need to remove them from the x.data
file. Your file should look something like this:
1
10
1110101
1110110
1110111
However, I still get simulator warnings because the simulator interprets 1110101
as a hexadecimal value. Since this value is too large for the 12-bit variable, the simulator does not load it into rom
, leaving the value as the default x
.
My guess is that your data is really binary format instead of hex. In that case, use $readmemb
instead of $readmemh
:
initial $readmemb("x.data", rom);
When I make that change, I no longer see x
.
Refer to IEEE Std 1800-2017, section 21.4 Loading memory array data from a file for detailed syntax.