Recently, when writing testbench for simulation, I learned a method of reading data from a text file and passing it to memory, and then performing simulation. I will briefly record it here.
1. First define the parameters and the two-dimensional array memory.
2. Use $readmemh to read the data in the text file into memory.
parameter WORDSIZE=8;
parameter MEM_DEPTH=32;
reg [WORDSIZE-1:0] mem1 [MEM_DEPTH-1:0];
//定义一个二维memory,共有MEM_DEPTH个单元,每个单元WORDSIZE个bit
initial begin
$readmemh("../rtl/mem_1.txt",mem1);
//将mem_1.txt中的数据读入mem1当中
end