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.

how to read a file from verilog

Status
Not open for further replies.

Tajwar

Newbie level 6
Joined
May 19, 2013
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,404
can any1 tell me how to read a file in verilog?

- - - Updated - - -

where do v add data.txt file? as a module or as a test bench ?
 

in the testbench or top module u can use the $readmemb for reading file.
do refer verilog LRM it will give u every ans u need

syntax: $readmemb("file_name.ext", var_name);
 

I am trying this code for reading a text file. but when i simulate it, my output at Mem is XXXXXXXXXX . can any1 help me whr i am rong??

module readmemh_demo;
reg [31:0] Mem [0:11];
initial $readmemh("data.txt",Mem);
integer k;
initial begin
#10;
$display("Contents of Mem after reading data file:");
for (k=0; k<6; k=k+1) $display("%d:%h",k,Mem[k]);
end
endmodule
EXAMPLE: data.txt file
234ac
23ca5
b3c34
23a4a
234ca
b3234
 

I am trying this code for reading a text file. but when i simulate it, my output at Mem is XXXXXXXXXX . can any1 help me whr i am rong??

module readmemh_demo;
reg [31:0] Mem [0:11];
initial $readmemh("data.txt",Mem);
integer k;
initial begin
#10;
$display("Contents of Mem after reading data file:");
for (k=0; k<6; k=k+1) $display("%d:%h",k,Mem[k]);
end
endmodule
EXAMPLE: data.txt file
234ac
23ca5
b3c34
23a4a
234ca
b3234

What does your verilog log file say?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top