Verilog readmemh (or readmemb) function.

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.

Step. Display the values from the text file on the compiler screen.

Readmemb is similar to readmemh with only difference of binary interpretation of the text file. Required format of input text file is binary.

SystemVerilog Parameters passingdefparam & localparam

LTE - 4G Wireless Technology

Digital fundamentals.

Interview Questions.

~\Documents\fullchip\python\mysite\webpages\templates\webpages\test.v.html
// 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];

// initialize 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;

/*read and display the values from the text file on screen*/

initial begin

     $display("rdata:");

     for (i=0; i < 4; i=i+1)

     $display("%d:%h",i,data[i]);

end

endmodule

Results

Input => File vectors.txt =>

12abc 34def 1dead 2bee1

Output =>

0:12abc

1:34def

2:1dead

3:2bee1

Tutorials @fullchipdesign.com

Verilog Tutorial.

LTE Tutorial.

Memory Tutorial.

Hope you liked! this page. Don't forgot to access relevant previous and next sections with links below.