# How to write a Verilog program to read binary data from text file?

Status
Not open for further replies.

#### suganthitechno

##### Newbie level 2
How to write a Verilog program with large input size - 1024 bytes? any shortcut?

hi,
I am trying to develop verilog code for 1024 individual byte input..verilog does not allow array of vectors as input or output..i know i can use reg [7:0]mem[1023:0] and assign inputs to mem. but do i have to type all 1024 datas in portlist or is there any shortcut?

#### FvM

##### Super Moderator
Staff member
Re: How to write a Verilog program with large input size - 1024 bytes? any shortcut?

You have two options
- refer to Systemverilog enhancements of Verilog language
- remember 8*1024 = 8192

#### suganthitechno

##### Newbie level 2
hi
I need to read 1024 bytes from text file in binary form.
In my program , i have memory [7:0]mem[1023:0] and i need to write binary data from text file to this mem. After getting binary data into the mem, i have to do some image processing manipulation(texture analysis) and write the result into another text file in binary form or any other form.
Can anyone post the detailed code to read binary data from file and to write in another file?
Also iam currently using modelsim..does file reading and writing work in xilinx?

#### Gayathrirani

##### Newbie level 4
I've done reading part alone.Here is the code to read 1024 bytes fom memory.The image should be first converted to text with hex values using MATLAB.
reg [7:0] data_1 [0:1023];
initial $readmemh("lenaimghex.txt", data_1); integer i; initial begin$display("rdata:");
for (i=0; i < 1024; i=i+1)
\$display("%d:%h",i,data_1);
end
endmodule
I've referred it from some other website.display is not necessary.Note that you've the text file inthe same folder as that of the verilog file.

karnatilakshmi

Points: 2