Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

File reading and writing in verilog

Status
Not open for further replies.

kommu4946

Member level 4
Member level 4
Joined
Feb 21, 2014
Messages
71
Helped
13
Reputation
26
Reaction score
11
Trophy points
1,288
Location
India
Visit site
Activity points
1,846
Hi All,

I have written a verilog code to interchange 3 X 3 matrix rows and columns.I am just reading a file and writing into another new file and also i want to read first row of resultant matrix .Here is the code

Code Verilog - [expand]
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


The above code is writing into a new file but unable to read into another variable [2:0]a why?
and also can i use same integer variable for fscanf when each time it is used and each time it is returning the same value 3 why?. I studied reference manual they explained file descriptor and mcd for only fopen.PLEASE HELP ME..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top