Quick Reference Verilog HDL
Quick Reference Verilog HDL
Reference
for
Verilog HDL
Rajeev Madhavan
AMBIT Design Systems, Inc.
Rajeev Madhavan
AMBIT Design Systems, Inc.
For additional copies of this book or for the source code to the
examples, see the order form on the last page of the book.
ISBN 0-9627488-4-6
Quick Reference for Verilog HDL
Preface
This is a brief summary of the syntax and semantics of the Ver-
ilog Hardware Description Language. The summary is not
intended at being an exhaustive list of all the constructs and is
not meant to be complete. This reference guide also lists con-
structs that can be synthesized. For any clarifications and to
resolve ambiguities please refer to the Verilog Language Refer-
c
ence Manual, Copyright 1993 by Open Verilog Interna-
tional, Inc. and synthesis vendors Verilog HDL Reference
Manuals.
Rajeev Madhavan
Quick Reference
for
Verilog HDL
1.0 Lexical Elements ....................................................................... 1
1.1 Integer Literals .............................................................. 1
1.2 Data Types..................................................................... 1
2.0 Registers and Nets ..................................................................... 2
3.0 Compiler Directives................................................................... 3
4.0 System Tasks and Functions...................................................... 4
5.0 Reserved Keywords................................................................... 5
6.0 Structures and Hierarchy ........................................................... 6
6.1 Module Declarations ..................................................... 6
6.2 UDP Declarations.......................................................... 7
7.0 Expressions and Operators ...................................................... 10
7.1 Parallel Expressions .................................................... 13
7.2 Conditional Statements ............................................... 13
7.3 Looping Statements..................................................... 15
8.0 Named Blocks, Disabling Blocks............................................ 16
9.0 Tasks and Functions................................................................. 16
10.0 Continous Assignments ........................................................... 18
11.0 Procedural Assignments .......................................................... 18
11.1 Blocking Assignment ................................................ 19
11.2 Non-Blocking Assignment ........................................ 19
12.0 Gate Types, MOS and Bidirectional Switches ........................ 19
12.1 Gate Delays ............................................................... 21
13.0 Specify Blocks......................................................................... 22
14.0 Verilog Synthesis Constructs ................................................... 23
14.1 Fully Supported Constructs....................................... 23
14.2 Partially Supported Constructs.................................. 24
14.3 Ignored Constructs .................................................... 25
14.4 Unsupported Constructs ............................................ 25
15.0 Index ........................................................................................ 27
1
Quick Reference for Verilog HDL
time newtime ;
/* time and integer are similar in functionality,
time is an unsigned 64-bit used for time variables
*/
initial begin
a = 0.5 ; // same as 5.0e-1. real variable
b = 1.2E12 ;
c = 26.19_60_e-11 ; // _’s are
// used for readability
string = “ string example ” ;
newtime =$time;
end
wire tri
wand triand
wor trior
tri0 tri1
supply0 supply1
trireg
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
then the wire resolves to the non z value. If two or more non z drivers
have different drive strength, then the wire resolves to the stronger
driver. If two drivers of equal strength have different values, then the
2
Quick Reference for Verilog HDL
wire net1 ;
/* wire and tri have same functionality. tri is
used for multiple drive internal wire */
Memories are declared using register statements with the address range
specified as in the following example,
The keyword scalared allows access to bits and parts of a bus and
vectored allows the vector to be modified only collectively.
3
Quick Reference for Verilog HDL
4
Quick Reference for Verilog HDL
5
Quick Reference for Verilog HDL
endmodule
6
Quick Reference for Verilog HDL
module dff_lab;
reg data,rst;
// Connecting ports by name.(map)
dff d1 (.qb(outb), .q(out),
.clk(clk),.d(data),.rst(rst));
// overriding module parameters
defparam
dff_lab.dff.n1.delay1 = 5 ,
dff_lab.dff.n2.delay2 = 6 ;
// full-path referencing is used
// over-riding by using #(8,9) delay1=8..
7
Quick Reference for Verilog HDL
table
endtable
endprimitive
8
Quick Reference for Verilog HDL
table
endtable
endprimitive
9
Quick Reference for Verilog HDL
• Unary Expression
<operator> <operand>
a = !b;
if (a < b ) // if (<expression>)
{c,d} = a + b ;
// concatenate and add operator
Operator Precedence
*, / %
+, - (binary)
<<. >>
=, ==. !=
===, !==
&, ~&
^, ^~
|, ~|
&&
||
?: Lowest
10
Quick Reference for Verilog HDL
Operator Application
Arithmetic Operators
Operator Application
* c = a * b ; // multiply a with b
/ c = a / b ; // int divide a by b
- diff = a - b ; // subtract b
// from a
% amodb = a % b ; // a mod(b)
Logical Operators
Operator Application
|| a || b ; // is a or b true?
// returns 1-bit true/false
11
Quick Reference for Verilog HDL
Operator Application
= c = a ; // assign a to c
== c == a ; /* is c equal to a
returns 1-bit true/false
applies for 1 or 0, logic
equality, using X or Z oper-
ands returns always false
‘hx == ‘h5 returns 0 */
!= c != a ; // is c not equal to
// a, retruns 1-bit true/
// false logic equality
Operator Application
| b = |a ; // OR all bits
12
Quick Reference for Verilog HDL
Operator Application
?: c = sel ? a : b ; /* if sel
is true c = a, else c = b ,
?: ternary operator */
{} {co, sum } = a + b + ci ;
/* add a, b, ci assign the
overflow to co and the re-
sult to sum: operator is
called concatenation */
initial
begin: block
fork
// This waits for the first event a
// or b to occur
@a disable block ;
@b disable block ;
13
Quick Reference for Verilog HDL
14
Quick Reference for Verilog HDL
casex (state)
// treats both x and z as don’t care
// during comparison : 3’b01z, 3’b01x, 3b’011
// ... match case 3’b01x
3’b01x: fsm = 0 ;
3’b0xx: fsm = 1 ;
default: begin
// default matches all other occurances
fsm = 1 ;
next_state = 3’b011 ;
end
endcase
casez (state)
// treats z as don’t care during comparison :
// 3’b11z, 3’b1zz, ... match 3’b1??: fsm = 0 ;
3’b1??: fsm = 0 ; // if MSB is 1, matches 3?b1??
3’b01?: fsm = 1 ;
default: $display(“wrong state”) ;
endcase
forever
// should be used with disable or timing control
@(posedge clock) {co, sum} = a + b + ci ;
repeat(bit-width) begin
if (a[0]) out = b + out ;
b = b << 1 ; // muliplier using
a = a << 1 ; // shift left and add
end
15
Quick Reference for Verilog HDL
Tasks Functions
16
Quick Reference for Verilog HDL
task Example
// task are declared within modules
task recv ;
output valid ;
output [9:0] data ;
begin
valid = inreg ;
if (valid) begin
ackin = 1 ;
data = qin ;
wait(inreg) ;
ackin = 0 ;
end
end
// task instantiation
always begin: MAIN //named definition
if (!qfull) begin
recv(new, newdata) ; // call task
if (new) begin
q[head] = newdata ;
head = head + 1 ;
end
end else
disable recv ;
end // MAIN
function Example
17
Quick Reference for Verilog HDL
always @(rst)
// procedural assignment with triggers
if (rst) assign q = temp;
else deassign q;
18
Quick Reference for Verilog HDL
19
Quick Reference for Verilog HDL
No strengths, rtran,rtranif0,
resistive rtranif1
Allows pullup
strengths pulldown
20
Quick Reference for Verilog HDL
21
Quick Reference for Verilog HDL
Delay Model
For trireg , the decay of the capacitive network is modeled using the
rise-time delay, fall-time delay and charge-decay. For example,
endspecify
22
Quick Reference for Verilog HDL
Verilog
Synthesis Constructs
The following is a set of Verilog constructs that are supported by most
synthesis tools at the time of this writing. To prevent variations in sup-
ported synthesis constructs from tool to tool, this is the least common
denominator of supported constructs. Tool reference guides cover spe-
cific constructs.
23
Quick Reference for Verilog HDL
disable
function, endfunction
if, else, else if
input, output, inout
wire, wand, wor, tri
integer, reg
macromodule, module
parameter
supply0, supply1
task, endtask
Construct Constraints
24
Quick Reference for Verilog HDL
25
Quick Reference for Verilog HDL
- NOTES -
26
Quick Reference for Verilog HDL
Symbols C
$display, $write 5 case 14
$fdisplay, $fwrite 5 casex 14
$finish 5 casez 14
$getpattern 5 compiler directives 3
$history 5 continous assignments 18
$hold, $width 5
$monitor, $fmonitor 5 D
$readmemb, $readmemh 5
delays 21
$save, $restart, $incsave 5
disable 16
$scale 5
$scope, $showscopes 5 E
$setup, $setuphold 5
$showvars 5 Equality Operators 12
$sreadmemb/$sreadmemh 5 Escaped identifiers 1
$stop 5 Expressions 10
$strobe, $fstrobe 5
$time, $realtime 5 F
/* */ 1
// 1 for 15
‘autoexpand_vectornets 4 forever 15
‘celldefine, ‘endcelldefine 4 fork ... join 13
‘default_nettype 4 Fully Supported Synthesis Con-
‘define 4 structs 23
‘expand_vectornets 4 function 16
‘noexpand_vectornets 4 G
‘ifdef, ‘else, ‘endif 4
‘include 4 Gate declaration 19
‘nounconnected_drive 4 gate-types 19
‘protect, ‘endprotect 4
‘protected, ‘endprotected 4 I
‘remove_gatename 4
‘noremove_gatenames 4 if, if ... else 13
‘remove_netname 4 Integer literals 1
‘noremove_netnames 4 Identity Operators 12
‘resetall 4
‘signed, ‘unsigned 4
L
‘timescale 4 Logical Operators 11
‘unconnected_drive 4
M
A
Memories 3
Arithmetic Operators 11 module 6
B N
Binary Expressions 10 Named blocks 16
blocking assignment 19 Nets 2
non-blocking assignments 19
27
Quick Reference for Verilog HDL
O V
Operator precedence 10 vectored 3
P W
Partially Supported Synthesis wait 16
Constructs 24 wand 3
procedural assignments 18 while 15
pulldown 3 wire 2
pullup 3 wor 3
R X
reg, register 2 x, X 1
Relational Operators 11
repeat 15 Z
reserved words 5
z, Z 1
S
scalared 3
Sequential edge sensitive UDP 9
Sequential level sensitive UDP 9
Shift, other Operators 13
specify block 22
specparam 22
String symbols 1
supply0 3
supply1 3
switch types 20
Synthesis Constructs 23
Synthesis Ignored Constructs 25
Synthesis Unsupported Con-
structs 25
T
task 16
tri0 3
tri1 3
triand 3
trior 3
trireg 3
U
UDP 7
Unary Expression 10
Unary, Bitwise and Reduction
Operators 12
28
Verilog HDL Publications Order Form
Automata Publishing Company
1072 S. Saratoga Sunnyvale Rd., Bldg. A107, Ste 325,
San Jose CA-95129. U.S.A
Phone: 408-255-0705 Fax: 408-253-7916
Verilog Publications:
Publication 1.Digital Design and Synthesis with Verilog HDL
Publication 2.Digital Design and Synthesis with Verilog HDL+
Source diskette + Quick Reference for Verilog HDL
Publication 1 2
Quantity
Publication 1 2
Qty-Price/copy (US$) (US$)
45 - 99 39.95 44.45
Rajeev Madhavan
ISBN 0-9627488-4-6