Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to $readmemh in Verilog

Tags:

verilog

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?

like image 254
node ninja Avatar asked Dec 10 '11 20:12

node ninja


1 Answers

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

like image 159
toolic Avatar answered Oct 12 '22 01:10

toolic