Home.Verilog.Digital Design.Digital Basics.Python.RF Basics.
Previous.
Next.
Custom Search

Legal Disclaimer

Chip Designing for ASIC/ FPGA Design engineers and Students
FULLCHIPDESIGN
Digital-logic Design...  Dream for many students… start learning front-end…

Legal Disclaimer

@TYH :- 4G LTE Long Term Evolution Tutorial, CloudComputing
PICS
Verilog Tutorial.
Get Noticed:- Submit your own content to be published on fullchipdesign.com

Send it to fullchip@gmail.com

Digital Basics Tutorial.

 

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

 

/* read and display the values from the tesxt 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 

 

Verilog readmemh function

Results

Input => File vectors.txt =>

12abc  34def  1dead 2bee1

Output =>

0:12abc

1:34def

2:1dead

3:2bee1

 

 

Following program is discussed in this section

Program. File operation using ‘readmemh’ for reading hexadecimal values from test files. 

Step. Verilog code example for file operations
Step.  Declare a array 4 word deep 20 locations wide for 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.