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
Visit site
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
 


What does your verilog log file say?
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…