VerilogQuickRef PDF
VerilogQuickRef PDF
VerilogQuickRef PDF
Quick
intended at being an exhaustive list of all the constructs and is
UNIX is a registered trademark of AT&T not meant to be complete. This reference guide also lists con-
Verilog is a registered trademark of Cadence Design Systems, Inc. structs that can be synthesized. For any clarifications and to
resolve ambiguities please refer to the Verilog Language Refer-
Verilog HDL text book is recommended: Digital Design and Synthesis With
Verilog HDL, Eli Sternheim, Rajvir Singh, Rajeev Madhavan
c
and Yatin Trivedi, Copyright 1993 by Automata Publishing
In addition to this book, the following HDL books are available Company.
from Automata Publishing Company:
For additional copies of this book or for the source code to the
Rajeev Madhavan examples, see the order form on the last page of the book.
AMBIT Design Systems, Inc. This book may be reproduced or transmitted for distribution provided
the copyright notices are retained on all copies. For all other rights
please contact the publishers.
1.0 Lexical Elements ....................................................................... 1 Permission to use, copy and distribute this book for any
1.1 Integer Literals .............................................................. 1 purpose is hereby granted without fee, provided that
1.2 Data Types..................................................................... 1
2.0 Registers and Nets ..................................................................... 2 (i) the above copyright notices and this permission
notice appear in all copies, and
3.0 Compiler Directives................................................................... 3
4.0 System Tasks and Functions...................................................... 4 (ii) the names of Rajeev Madhavan, Automata Publish-
5.0 Reserved Keywords................................................................... 5 ing and AMBIT Design Systems may not be used in any
advertising or publicity relating to this book without the
6.0 Structures and Hierarchy ........................................................... 6
specific, prior written permission of Rajeev Madhavan,
6.1 Module Declarations ..................................................... 6
Automata Publishing and AMBIT Design Systems.
6.2 UDP Declarations.......................................................... 7
7.0 Expressions and Operators ...................................................... 10 THE BOOK IS PROVIDED "AS-IS" AND WITH-
7.1 Parallel Expressions .................................................... 13 OUT WARRANTY OF ANY KIND, EXPRESS,
7.2 Conditional Statements ............................................... 13 IMPLIED OR OTHERWISE, INCLUDING WITH-
7.3 Looping Statements..................................................... 15 OUT LIMITATION, ANY WARRANTY OF MER-
8.0 Named Blocks, Disabling Blocks............................................ 16 CHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE.
9.0 Tasks and Functions................................................................. 16
10.0 Continous Assignments ........................................................... 18 IN NO EVENT SHALL RAJEEV MADHAVAN OR
11.0 Procedural Assignments .......................................................... 18 AUTOMATA PUBLISHING OR AMBIT DESIGN
11.1 Blocking Assignment ................................................ 19 SYSTEMS BE LIABLE FOR ANY SPECIAL, INCI-
11.2 Non-Blocking Assignment ........................................ 19 DENTAL, INDIRECT OR CONSEQUENTIAL DAM-
AGES OF ANY KIND, OR ANY DAMAGES
12.0 Gate Types, MOS and Bidirectional Switches ........................ 19
WHATSOEVER RESULTING FROM LOSS OF USE,
12.1 Gate Delays ............................................................... 21
PROFITS, WHETHER OR NOT ADVISED OF THE
13.0 Specify Blocks......................................................................... 22 POSSIBILITY OF DAMAGE, AND ON ANY THE-
14.0 Verilog Synthesis Constructs ................................................... 23 ORY OF LIABILITY, ARISING OUT OF OR IN CON-
14.1 Fully Supported Constructs....................................... 23 NECTION WITH THE USE OF THIS BOOK.
14.2 Partially Supported Constructs.................................. 24
14.3 Ignored Constructs .................................................... 25
14.4 Unsupported Constructs ............................................ 25
15.0 Index ........................................................................................ 27
1.0 Lexical Elements Time, registers and variable usage wire resolves to x. A trireg net behaves like a wire except that
when all the drivers of the net are in high impedance (z) state, then the
The language is case sensitive and all the keywords are lower case. time newtime ; net retains its last driven value. trireg ’s are used to model capaci-
White space, namely, spaces, tabs and new-lines are ignored. Verilog /* time and integer are similar in functionality, tive networks.
has two types of comments: time is an unsigned 64-bit used for time variables
*/ wire net1 ;
1. One line comments start with // and end at /* wire and tri have same functionality. tri is
the end of the line reg [8*14:1] string ; used for multiple drive internal wire */
/* This defines a vector with range
2. Multi-line comments start with /* and end [msb_expr: lsb_expr] */ trireg (medium) capacitor ;
with */ /* small, medium, weak are used for charge
initial begin strength modeling */
Variable names have to start with an alphabetic character or underscore a = 0.5 ; // same as 5.0e-1. real variable
followed by alphanumeric or underscore characters. The only excep- b = 1.2E12 ;
tion to this are the system tasks and functions which start with a dollar c = 26.19_60_e-11 ; // _’s are
sign. Escaped identifiers (identifier whose first characters is a backslash // used for readability A wand net or triand net operates as a wired and(wand), and a wor
( \ )) permit non alphanumeric characters in Verilog name. The string = “ string example ” ; net or trior net operates as a wired or (wor), tri0 and tri1 nets
newtime =$time;
escaped name includes all the characters following the backslash until model nets with resistive pulldown or pullup devices on them. When
end
the first white space character. a tri0 net is not driven, then its value is 0. When a tri1 net is not
driven, then its value is 1. supply0 and supply1 model nets that are
connected to the ground or power supply.
1.1 Integer Literals 2.0 Registers and Nets
A register stores its value from one assignment to the next and is used wand net2 ; // wired-and
Binary literal 2’b1Z wor net3 ; // wired-or
Octal literal 2’O17 to model data storage elements.
triand [4:0] net4 ; // multiple drive wand
Decimal literal 9 or ’d9 trior net5 ; // multiple drive wor
Hexadecimal literal 3’h189 reg [5:0] din ; tri0 net6 ;
/* a 6-bit vector register: individual bits tri1 net7 ;
din[5],.... din[0] */ supply0 gnd ; // logic 0 supply wire
Integer literals can have underscores embedded in them for improved supply1 vcc ; // logic 1 supply wire
readability. For example,
Nets correspond to physical wires that connect instances. The default Memories are declared using register statements with the address range
Decimal literal 24_000 range of a wire or reg is one bit. Nets do not store values and have to specified as in the following example,
be continuously driven. If a net has multiple drivers (for example two
reg [15:0] mem16X512 [0:511];
gate outputs are tied together), then the net value is resolved according
1.2 Data Types to its type.
// 16-bit by 512 word memory
// mem16X512[4] addresses word 4
The values z and Z stand for high impedance, and x and X stand for Net types // the order lsb:msb or msb:lsb is not important
uninitialized variables or nets with conflicting drivers. String symbols
wire tri The keyword scalared allows access to bits and parts of a bus and
are enclosed within double quotes ( “string” ).and cannot span multi- wand triand
vectored allows the vector to be modified only collectively.
ple lines. Real number literals can be either in fixed notation or in sci- wor trior
entific notation. tri0 tri1
supply0 supply1 wire vectored [5:0] neta;
Real and Integer Variables example /* a 6-bit vectored net */
trireg
tri1 vectored [5:0] netb;
real a, b, c ; // a,b,c to be real /* a 6-bit vectored tri1 */
For a wire, if all the drivers have the same value then the wire
resolves to this value. If all the drivers except one have a value of z
integer j, k ; // integer variable then the wire resolves to the non z value. If two or more non z drivers
integer i[1:32] ; // array of integer variables 3.0 Compiler Directives
have different drive strength, then the wire resolves to the stronger
driver. If two drivers of equal strength have different values, then the Verilog has compiler directives which affect the processing of the input
1 2 3
Quick Reference for Verilog HDL Quick Reference for Verilog HDL Quick Reference for Verilog HDL
files. The directives start with a grave accent ( ‘ ) followed by some A list of standard system tasks and functions are listed below: 6.0 Structures and Hierarchy
keyword. A directive takes effect from the point that it appears in the
file until either the end of all the files, or until another directive that $display, $write - utility to display information Hierarchical HDL structures are achieved by defining modules and
cancels the effect of the first one is encountered. For example, $fdisplay, $fwrite - write to file instantiating modules. Nested module definitions (i.e. one module defi-
$strobe, $fstrobe - display/write simulation data nition within another) are not permitted.
$monitor, $fmonitor - monitor, display/write information to file
‘define OPCODEADD 00010
$time, $realtime - current simulation time
$finish - exit the simulator 6.1 Module Declarations
This defines a macro named OPCODEADD. When the text ‘OPCODEADD $stop - stop the simulator
appears in the text, then it is replaced by 00010. Verilog macros are $setup - setup timing check The module name must be unique and no other module or primitive can
simple text substitutions and do not permit arguments. $hold, $width- hold/width timing check have the same name. The port list is optional. A module without a port
$setuphold - combines hold and setup
$readmemb/$readmemh - read stimulus patterns into memory
list or with an empty port list is typically a top level module. A macro-
`ifdef SYNTH <Verilog code> ‘endif $sreadmemb/$sreadmemh - load data into memory module is a module with a flattened hierarchy and is used by some sim-
$getpattern - fast processing of stimulus patterns ulators for efficiency.
If ‘‘SYNTH’’ is a defined macro, then the Verilog code until ‘endif is $history - print command history
inserted for the next processing phase. If ‘‘SYNTH’’ is not defined macro $save, $restart, $incsave module definition example
then the code is discarded. - saving, restarting, incremental saving
$scale - scaling timeunits from another module
$scope - descend to a particular hierarchy level module dff (q,qb,clk,d,rst);
`include <Verilog file> $showscopes - complete list of named blocks, tasks, modules... input clk,d,rst ; // input signals
$showvars - show variables at scope output q,qb ; // output definition
The code in <Verilog file> is inserted for the next processing
phase. Other standard compiler directives are listed below: //inout for bidirectionals
‘resetall - resets all compiler directives to default values 5.0 Reserved Keywords // Net type declarations
‘define - text-macro substitution wire dl,dbl ;
‘timescale 1ns / 10ps - specifies time unit/precision The following lists the reserved words of Verilog hardware description
‘ifdef, ‘else, ‘endif - conditional compilation language, as of OVI LRM 2.0. // parameter value assignment
‘include - file inclusion paramter delay1 = 3,
‘signed, ‘unsigned - operator selection (OVI 2.0 only) and always assign attribute delay2 = delay1 + 1; // delay2
‘celldefine, ‘endcelldefine - library modules begin buf bufif0 bufif1
case cmos deassign default // shows parameter dependance
‘default_nettype wire - default net types
‘unconnected_drive pull0|pull1, defparam disable else endattribute
‘nounconnected_drive - pullup or down unconnected ports end endcase endfunction endprimitive /* Hierarchy primitive instantiation, port
‘protect and ‘endprotect - encryption capability endmodule endtable endtask event connection in this section is by
‘protected and ‘endprotected - encryption capability for force forever fork ordered list */
‘expand_vectornets, ‘noexpand_vectornets, function highz0 highz1 if
‘autoexpand_vectornets - vector expansion options initial inout input integer
nand #delay1 n1(cf,dl,cbf),
‘remove_gatename, ‘noremove_gatenames join large medium module
- remove gate names for more than one instance nand negedge nor not n2(cbf,clk,cf,rst);
‘remove_netname, ‘noremove_netnames notif0 notif1 nmos or nand #delay2 n3(dl,d,dbl,rst),
- remove net names for more than one instance output parameter pmos posedge n4(dbl,dl,clk,cbf),
primitive pulldown pullup pull0 n5(q,cbf,qb),
pull1 rcmos reg release n6(qb,dbl,q,rst);
repeat rnmos rpmos rtran
4.0 System Tasks and Functions rtranif0 rtranif1 scalared small /***** for debuging model initial begin
specify specparam strong0 strong1
supply0 supply1 table task #500 force dff_lab.rst = 1 ;
System taska are tool specific tasks and functions.. #550 release dff_lab.rst;
tran tranif0 tranif1 time
tri triand trior trireg // upward path referencing
$display( “Example of using function”); tri0 tri1 vectored wait end ********/
/* display to screen */ wand weak0 weak1 while
$monitor($time, “a=%b, clk = %b, wire wor endmodule
add=%h”,a,clk,add); // monitor signals
$setuphold( posedge clk, datain, setup, hold);
// setup and hold checks
4 5 6
Quick Reference for Verilog HDL Quick Reference for Verilog HDL Quick Reference for Verilog HDL
7 8 9
Quick Reference for Verilog HDL Quick Reference for Verilog HDL Quick Reference for Verilog HDL
7.0 Expressions and Operators • All operators associate left to right, except for the Equality and Identity Operators
ternary operator “?:” which associates from right to
Arithmetic and logical operators are used to build expressions. Expres- left.
sions perform operation on one or more operands, the operands being Operator Application
vectored or scalared nets, registers, bit-selects, part selects, function Relational Operators
= c = a ; // assign a to c
calls or concatenations thereof.
== c == a ; /* is c equal to a
• Unary Expression Operator Application
returns 1-bit true/false
<operator> <operand> applies for 1 or 0, logic
< a < b // is a less than b?
equality, using X or Z oper-
// return 1-bit true/false
a = !b; ands returns always false
> a > b // is a greater than b? ‘hx == ‘h5 returns 0 */
10 11 12
Quick Reference for Verilog HDL Quick Reference for Verilog HDL Quick Reference for Verilog HDL
Shift Operators and other Operators if .. else ...conditions example casex statement example
13 14 15
Quick Reference for Verilog HDL Quick Reference for Verilog HDL Quick Reference for Verilog HDL
8.0 Named Blocks, Disabling Blocks task Example 10.0 Continous Assignments
// task are declared within modules
Named blocks are used to create hierarchy within modules and can be task recv ; Continous assignments imply that whenever any change on the RHS of
used to group a collection of assignments or expressions. disable output valid ; the assignment occurs, it is evaluated and assigned to the LHS. These
statement is used to disable or de-activate any named block, tasks or output [9:0] data ; assignments thus drive both vector and scalar values onto nets. Conti-
modules. Named blocks, tasks can be accessed by full or reference begin nous assignments always implement combinational logic (possibly
hierarchy paths (example dff_lab.stimuli).Named blocks can valid = inreg ; with delays). The driving strengths of a continous assignment can be
have local variables. if (valid) begin specified by the user on the net types.
ackin = 1 ;
Named blocks and disable statement example
data = qin ;
• Continous assignment on declaration
wait(inreg) ;
initial forever @(posedge reset) ackin = 0 ; /* since only one net15 declaration exists in a
disable MAIN ; // disable named block end given module only one such declarative continous
// tasks, modules can also be disabled end assignment per signal is allowed */
always begin: MAIN // defining named blocks // task instantiation wire #10 (atrong1, pull0) net15 = enable ;
if (!qfull) begin always begin: MAIN //named definition /* delay of 10 for continous assignment with
#30 recv(new, newdata) ; // call task if (!qfull) begin strengths of logic 1 as strong1 and logic 0 as
if (new) begin recv(new, newdata) ; // call task pull0 */
q[head] = newdata ; if (new) begin
head = head + 1 ; // queue q[head] = newdata ;
end • Continous assignment on already declared nets
head = head + 1 ;
end end
else assign #10 net15 = enable ;
end else
disable recv ; assign (weak1, strong0) {s,c} = a + b ;
disable recv ;
end // MAIN end // MAIN
16 17 18
Quick Reference for Verilog HDL Quick Reference for Verilog HDL Quick Reference for Verilog HDL
19 20 21
Quick Reference for Verilog HDL Quick Reference for Verilog HDL Quick Reference for Verilog HDL
Verilog
Delay Model disable
function, endfunction
#(delay) min:typ:max delay Synthesis Constructs if, else, else if
#(delay, delay) rise-time delay, fall-time delay, input, output, inout
each delay can be with The following is a set of Verilog constructs that are supported by most wire, wand, wor, tri
min:typ:max synthesis tools at the time of this writing. To prevent variations in sup- integer, reg
22 23 24
Quick Reference for Verilog HDL Quick Reference for Verilog HDL Quick Reference for Verilog HDL
25 26 26b
Quick Reference for Verilog HDL Quick Reference for Verilog HDL
27 28