Home Verilog Digital Design Digital Basics Python RF Basics

Legal Disclaimer

Chip Designing for ASIC/ FPGA Design engineers and Students
Digital-logic Design...  Dream for many students… start learning front-end…
Topics @TYH :- 4G LTE Tutorial, GVIM editor, Smart-Phone, Cloud Computing
Custom Search

Feedback ? Send it to admin@fullchipdesign.com or join me at fullchip@gmail.com

Legal Disclaimer

Introduction Operators Initial stms Block vs. Non Blk IF-ELSE, CASE FORLOOP File Operations Read .bin format Function Call Testbench Random Numbers Shift Micro-ops Sync RAM Mem Generate Assertions Signed RTL
Verilog Tutorial.
Digital Basics Tutorial.

StepDisplay 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


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





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.

Verilog readmemh (or readmemb) function in rtl

Following program is discussed in this section







Input => File vectors.txt =>

12abc  34def  1dead 2bee1

Output =>







Readmemb is similar to readmemh with only difference of binary interpretation of the text file. So if the readmemb is specified the required format of input text file is binary.   
File Operations.
Function Call.
Do you like Brain teasers?
Q. Simplify Boolean Functions F = xyz + x’y + xyz’.
Answer: click here Digital Logic fundamentals