0

I have a multi-dimensional array:

logic [7:0] memory[1:0][1:0];

and a comma-separated file.txt:

1,2
3,4

I am not able to load this file with $readmemh:

initial
begin
   $readmemh("file.txt", memory);
end

Could you suggest a solution?

1
  • 1
    As the answer below already deals with what will work, Ill just mention this in a comment; the problem specifically is the commas, readmem files can only contain white space, comments, addresses and/or numbers (either binary for readmemb or hex for readmemh). So, to separate values, just use spaces and/or new lines. See section 21.4 of the 2012 LRM. Commented Oct 10, 2019 at 22:36

1 Answer 1

1
logic [7:0] mem [1:0][1:0]

For the above 4 elements array each of 8 bits. Define the mem.dat file as follows

01 02
03 04

Then read the file in one shot using readmemh

initial
begin
   $readmemh("mem.dat", mem);
end
Sign up to request clarification or add additional context in comments.

1 Comment

Your example would be even more helpful if both unpacked array ranges were not the same, [3:0][1:0] for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.