I'm trying to load values from a file into a two-dimensional array like this.
reg [31:0] RAM[63:0];
initial
$readmemh("memory.dat",RAM);
What are the alternatives? If I wanted to hardcode the values stored in the memory instead, what's the code to do that?
If you want to hardcode the values, just assign to each memory location:
initial begin
RAM[0] = 32'h1234_5678;
RAM[1] = 32'h9abc_def0;
RAM[2] = 32'haaaa_5555;
// etc.
end
Another alternative to $readmemh
is to use the file IO system tasks, such as $fopen
and $fscanf
(refer to the IEEE Standard or your simulator documentation).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With