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.