1. fopen
string file_name;
int file_handle;
initial begin
file_handle = $fopen(file_name,"r"); //只读方式打开;
while(!$feof(file_handle))
$fscanf(file_handle,"%s %d",s, i); //获得数据;
end
2. readmemh/readmemb tasks,由于memory文件中只能有数字,空格和注释,所以一般用在读取纯数字文件;
$readmemb ( " file_name " , memory_name [ , start_addr [ , finish_addr ] ] ) ; //binary
$readmemh ( " file_name " , memory_name [ , start_addr [ , finish_addr ] ] ) ; //16进制
For example:
reg [7:0] mem[1:256];
Given this declaration, each of the following statements load data into mem in a different manner:
initial $readmemh("mem.data", mem);
initial $readmemh("mem.data", mem, 16);
initial $readmemh("mem.data", mem, 128, 1);
The first statement loads up the memory at simulation time 0 starting at the memory address 1. The second
statement begins loading at address 16 and continue on toward address 256. For the third and final
statement, loading begins at address 128 and continue down toward address 1.