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…
Custom Search

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

Verilog Initial stmts IF-ELSE Case stms Readmemh Function Testbench Binary to Gray Clock Crossing Half-adder Full-adder Tristate buffer Adder tb Counter_enable Blocking Operators Shift LSR Random Nos Sync RAM Verilog Tutorial

Legal Disclaimer

Topics @TYH :- 4G LTE Tutorial, GVIM editor, Smart-Phone, Cloud Computing
Previous Next
Verilog Tutorial.
Digital Basics Tutorial.

StepDisplay the values from the text file on the compiler screen.


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


        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


Input => File vectors.txt =>

12abc  34def  1dead 2bee1

Output =>







Do you like Brain teasers? Q. Simplify Boolean Functions F = xyz + x’y + xyz’.
Answer: click here Digital Logic fundamentals
Readmemb is similar to readmemh with only difference of binary interpretation of the text file. Required format of input text file is binary.   
Interview Questions. Main, FPGA, Digital Fundamentals
LTE - Long Term Evolution topics from here


Parameters passing, defparam & localparam

Alias, Array, Assertions