This is an excerpt from the Chapter 1 of the book Principles of Verilog PLI by Swapnajit Mittra published from Kluwer Academic Publishers. ISBN: 0-7923-8477-6 [All copyright reserved. No portion of this text can be used for for commercial purpose without explicit permission from the author nor can it be used for re-print in hardcopy or electronic form.] Order the book here.




A sample Verilog program containing the call $invert is shown below.

module mymodule;
reg [7:0] r1;
initial begin
r1 = 8'hf;
#100 $invert(r1); // Invert the content of r1
#100 $finish;

Assuming the code is saved in the file test.v, it is compiled for VCS to generate the executable binary pli_invert by giving the followingcommand.

$ vcs -o pli_invert -P test.vveriuser.c

Executing pli_invert, we get the following result.

Contains Chronologic Simulation proprietary information. Oct 21 00:05 1997

$invert: Modifying the content from00001111 to 11110000 at time 100
$finish at simulation time 200
V C S S im u l a t i o n R e p o r t
Time: 200
CPU Time: 0.067 seconds;Data structure size: 0.0Mb
Tue Oct 21 00:05:16 1997

Self-test :
Modify the PLI routine $invert() to create a new system call $twos_complement(), which takes a register as its argument and replacesits content by the two's complement of its present value. Remember, you should issue an error message and abort, if any bit of the register is Z or X.
Repeat the problem again, so that the modified value of the registerappears only 10 time units after the current simulation cycle.


In this chapter, we have learnt the basic structure of a PLI routine and mechanism of linking it to build a custom version of Verilog. We have also learnt how to read, convert and modify the values of elementary components of a design database in Verilog through PLI C code. And also how to read the simulation time. These are the basic and often the most needed tasks of a PLI code.

Compared to the rest of the universe that PLI offers, however, this is really a small part. In later chapters we will see how PLI can be used to access other design information not related to the basic component --name of the current module and its parent, or controlling the path-delays, for example.

Also we have so far used only the so-called 'utility routines' providedby PLI1.0. There is a complete different set of routines, known as'access routines', which is often recommended for more uniform interfacing.We will learn about it in Chapter 4.

All product names mentioned here are registered trademarks of their respective owner companies.

Previous Share/Save/Bookmark

Verification Management
Join Verification Management Group

Talk UVM with Friends
Shop Amazon - Contract Cell Phones & Service Plans

Fun Stuffs!