6

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?

toolic
  • 57,801
  • 17
  • 75
  • 117
node ninja
  • 31,796
  • 59
  • 166
  • 254

1 Answers1

5

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).

toolic
  • 57,801
  • 17
  • 75
  • 117