1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| module sim3(
);
integer i,fd1,fd2,n1,n2;
reg [3:0]row1[0:2];
reg [3:0]row2[0:2];
reg [3:0]row3[0:2];
reg [3:0]a[0:2];
initial begin
fd1=$fopen("input_matrix.txt","r");
fd2=$fopen("out_matrix.txt","r+");//open for update (reading and writing)
n1=$fscanf(fd1,"%d%d%d",row1[0],row1[1],row1[2]);
n1=$fscanf(fd1,"%d%d%d",row2[0],row2[1],row2[2]);
n1=$fscanf(fd1,"%d%d%d",row3[0],row3[1],row3[2]);
for(i=0;i<3;i=i+1) begin
$fwrite(fd2,"%d%d%d\n",row1[i],row2[i],row3[i]);
end
n2=$fscanf(fd2,"%d%d%d",a[0],a[1],a[2]);
$fclose(fd1);
$fclose(fd2);
end
endmodule |