
Feedback ? Send it to admin@fullchipdesign.com or join me at fullchip@gmail.com
Step. Display the values from the text file on the compiler screen.
Readmemb click here. Its used for reading binary numbers instead of hex.
// Verilog code example for file operations
// module declaration
module file_readmemh;
/* Declare a array 4 word deep 20 locations wide for 20/4 = 5 hexadecimal words */
reg [19:0] data [0:3];
// initalize the hexadecimal reads from the vectors.txt file
initial $readmemh("vectors.txt", data);
/* declare an integer for the conditional
statement to read values from test file */
integer i;
/* FOR loop to read and display the values from the text file on the compiler screen */
initial begin
$display("rdata:");
for (i=0; i < 4; i=i+1)
$display("%d:%h",i,data[i]);
end
endmodule
Program. File operation using ‘readmemh’ for reading hex values from test files.
Step. Verilog code example for file operations.
Step. Declare a array of 4 word deep and 20 locations wide to store 5 hexadecimal values.
Step. Use ‘readmemh’ command to read hexadecimal values.
Step. Declare an integer to set a pointer to read values from test file.
Following program is discussed in this section
Results
Input => File vectors.txt =>
12abc 34def 1dead 2bee1
Output =>
0:12abc
1:34def
2:1dead
3:2bee1