Basics in Verilog
Basics in Verilog
2
System Tasks
3
$display
4
5
$display example :
6
$monitor
7
$monitor example :
8
9
$display , $monitor , $strobe
�These three syntax have priorities while display
�$strobe has least priority compared to $display
�In-between $monitor and $strobe ,$monitor has least
priority
�Priority order:
$display ,$strobe ,$monitor
Ex: $display(”A”);
$display(“B”); OUTPUT: A
$monitor(“C”); B
$monitor(“D”); D
10
11
12
13
Randomization concept in verilog
Why Randomization?
�Direct Stimuli takes long time to develop all possible
scenarios to verify different features
�Random testing is used to find the unexpected bugs
14
15
16
EXAMPLE:
17
$urandom()
�Function generates 32-bit random number but it is
always unsigned
bit{31:0] d;
d=$urandom();
Integer seed =3;
Int b=$urandom(seed);
18
$urandom_range()
�It returns the unsigned values between specified range
Syntax:
$urandom_range(max,min);
19
File Operations
�$fopen opens an output file and gives the open file a
handle for use by the other commands.
�$fclose closes the file and lets other programs access it.
�$fdisplay and $fwrite write formatted data to a file
whenever they are executed. They are the same except
$fdisplay inserts a new line after every execution and
$write does not.
�$fstrobe also writes to a file when executed, but it waits
until all other operations in the time step are complete
before writing.
�$fmonitor writes to a file whenever any of its arguments
changes
20
File Operations - Usage
�handle1=$fopen("filenam1.suffix") ;
�handle2=$fopen("filenam2.suffix") ;
�$fstrobe(handle1, format, variable list); //strobe data
into filenam1.suffix
�$fdisplay(handle2, format, variable list); //write data
into filenam2.suffix
�$fwrite(handle2, format, variable list); //write data
into filenam2.suffix
21
Reading from a file
�$readmemh("filename.suffix“, mem) ; // To read a file
consists of HEX values
�$readmemb("filename.suffix“, mem) ; // To read a file
consists of BIN values
* mem is an array data type
22
Interview Questions
�Difference between $display and $monitor?
�Difference between $random and $urandom?
23
k y o u
Than
24