integer handle ;
always @(posedge clk)begin
if(rst) begin
handle = $fopen("data.txt");
$fdisplay(handle,"%h",16'h2);
$fclose(handle);
end else if( )begin
handle = $fopen("data.txt","a+");
$fdisplay(handle,"%h",16'h2);
$fclose(handle);
end
end
`timescale 1ns / 1ps
module file_test(
);
reg [3:0]data[0:15];
reg [3:0]data2[0:15];
integer handle1;
integer i=0;
initial
begin
$readmemb("num.txt",data);//默认文件在工程所在路径目录
handle1 = $fopen("num2.txt","w");
repeat(16)
begin
$fwrite(handle1,"%d\n",data[15-i]);
i = i+1;
end
$fclose(handle1);
end
endmodule
Verilog文件的读取(fscanf)和写入(fwrite)方法_re_call的博客-CSDN博客
Verilog中常见文件操作($readmemb,$fopen,$fwrite,$fclose)_CLL_caicai的博客-CSDN博客_$fwrite