Verilog
Quick Reference Guide
Author:Susmita Nayak
Email:tech_support@maven-silicon.com
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
Maven Silicon Confidential
All the presentations, books, documents [hard copies and soft copies] labs
and projects [source code] that you are using and developing as part of the training
course are the proprietary work of Maven Silicon and it is fully protected under
copyright and trade secret laws. You may not view, use, disclose, copy, or
distribute the materials or any information except pursuant to a valid written
license from Maven Silicon
Table Of Contents Copyright © 2020 Maven Silicon 2
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
Table of Contents
Data-types .............................................................................................................................................. 6
1.1 Nets: wire ............................................................................................................................... 6
1.1.1 wire ................................................................................................................................. 6
1.2 Registers/Variables: {reg, integer, real, time, string} ........................................................ 6
1.2.1 reg ................................................................................................................................... 6
1.2.2 integer............................................................................................................................. 7
1.2.3 real .................................................................................................................................. 7
1.2.4 time ................................................................................................................................. 8
1.2.5 string............................................................................................................................... 8
1.3 Vectors ................................................................................................................................... 8
1.4 Arrays..................................................................................................................................... 8
1.5 Parameter constants ............................................................................................................. 9
1.5.1 Parameter overriding ................................................................................................... 9
Operators ............................................................................................................................................. 10
2.1 Logical operators ................................................................................................................ 10
2.2 Bitwise operators ................................................................................................................. 10
2.3 Reduction operators............................................................................................................ 11
2.4 Shift operators ..................................................................................................................... 11
2.5 Equality operators .............................................................................................................. 12
2.6 Relational operators............................................................................................................ 12
2.7 Concatenation operators .................................................................................................... 13
2.8 Conditional operators ......................................................................................................... 13
2.9 Arithmetical operators ....................................................................................................... 13
Processes .............................................................................................................................................. 14
3.1 Continuous process ............................................................................................................. 14
3.1.1 Continuous concurrent process ................................................................................. 14
3.2 Procedural process .............................................................................................................. 14
3.2.1 initial, always ............................................................................................................... 14
3.3 Events ................................................................................................................................... 15
Table Of Contents Copyright © 2020 Maven Silicon 3
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
Structured procedures ........................................................................................................................ 16
4.1 Blocking assignment ........................................................................................................... 16
4.2 Non-blocking assignment ................................................................................................... 16
4.3 Tasks..................................................................................................................................... 16
4.4 Functions.............................................................................................................................. 17
4.5 Timing control statements .................................................................................................. 17
4.5.1 Delays: {Inertial, Regular, Intra-assignment} .......................................................... 17
4.5.2 Wait .............................................................................................................................. 18
4.5.3 Event based timing ...................................................................................................... 18
4.6 Procedural blocks................................................................................................................ 19
4.6.1 Sequential blocks ......................................................................................................... 19
4.6.2 Parallel blocks ............................................................................................................. 19
4.6.3 Named blocks .............................................................................................................. 19
4.6.4 Disable .......................................................................................................................... 20
4.6.5 Branching constructs: {if else, case} .......................................................................... 20
4.6.6 Looping constructs: {for, while, repeat, forever} ..................................................... 21
System tasks & functions.................................................................................................................... 23
5.1 Display system tasks ........................................................................................................... 23
5.1.1 $display, $write, $strobe, $monitor ........................................................................... 23
5.2 File operations ..................................................................................................................... 23
5.2.1 File write ...................................................................................................................... 23
5.2.2 File read ....................................................................................................................... 24
5.3 Simulation control system tasks......................................................................................... 24
5.3.1 $finish ........................................................................................................................... 24
5.3.2 $stop ............................................................................................................................. 24
5.4 Randomizing function ........................................................................................................ 25
5.4.1 $random ....................................................................................................................... 25
5.5 Command line input function ............................................................................................ 25
5.5.1 $test$plusargs .............................................................................................................. 25
5.6 Simulation time functions................................................................................................... 25
5.6.1 $time ............................................................................................................................. 25
5.6.2 $realtime ...................................................................................................................... 26
Table Of Contents Copyright © 2020 Maven Silicon 4
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
Compiler directives ............................................................................................................................. 27
6.1 `define ................................................................................................................................... 27
6.2 `include ................................................................................................................................. 27
6.3 `timescale ............................................................................................................................. 28
6.4 `ifdef ..................................................................................................................................... 28
Verilog examples ................................................................................................................................. 29
7.1 One bit full_adder using half_adder ................................................................................. 29
7.2 2:1 Multiplexer .................................................................................................................... 30
7.3 4:1 Multiplexer ................................................................................................................. 30
7.4 4:2 Priority Encoder ........................................................................................................... 31
7.5 2:4 decoder........................................................................................................................... 31
7.6 ALU ...................................................................................................................................... 32
7.7 DFF-Synchronous reset ...................................................................................................... 33
7.8 DFF-Asynchronous clear.................................................................................................... 33
7.9 Modulo 12 – Counter .......................................................................................................... 33
7.10 Dual port synchronous RAM – 256X8 .............................................................................. 34
7.11 Sequence detector-110(Moore overlapping) ..................................................................... 35
Table Of Contents Copyright © 2020 Maven Silicon 5
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
Data-types
1.1 Nets: wire
1.1.1 wire
wire is continuously driven by combinational logic. The default value of a wire is “z”.
1.2 Registers/Variables: {reg, integer, real, time, string}
1.2.1 reg
Reg is a variable which retains value till it is updated. The default value of reg is “x”.
Table Of Contents Copyright © 2020 Maven Silicon 6
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
1.2.2 integer
Integers are signed values. The default size is 32bits. The default value of an integer is “x”.
1.2.3 real
Real numbers are expressed with a decimal point shall have atleast one digit on each side of
the decimal point. The default value of real is 0.
Table Of Contents Copyright © 2020 Maven Silicon 7
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
1.2.4 time
Time variables shall behave same as reg of atleast 64 bits. It is unsigned with default value as
“x”.
1.2.5 string
Strings are sequence of characters which are enclosed within double quotes “ “ and each
character is stored as 8 bits ASCII value. They are stored as reg type variables.
1.3 Vectors
1.4 Arrays
Table Of Contents Copyright © 2020 Maven Silicon 8
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
1.5 Parameter constants
1.5.1 Parameter overriding
Table Of Contents Copyright © 2020 Maven Silicon 9
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
Operators
2.1 Logical operators
2.2 Bitwise operators
Table Of Contents Copyright © 2020 Maven Silicon 10
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
2.3 Reduction operators
2.4 Shift operators
Table Of Contents Copyright © 2020 Maven Silicon 11
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
2.5 Equality operators
2.6 Relational operators
Table Of Contents Copyright © 2020 Maven Silicon 12
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
2.7 Concatenation operators
2.8 Conditional operators
2.9 Arithmetical operators
Table Of Contents Copyright © 2020 Maven Silicon 13
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
Processes
3.1 Continuous process
3.1.1 Continuous concurrent process
3.2 Procedural process
3.2.1 initial, always
Table Of Contents Copyright © 2020 Maven Silicon 14
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
3.3 Events
Table Of Contents Copyright © 2020 Maven Silicon 15
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
Structured procedures
4.1 Blocking assignment
4.2 Non-blocking assignment
4.3 Tasks
Table Of Contents Copyright © 2020 Maven Silicon 16
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
4.4 Functions
4.5 Timing control statements
4.5.1 Delays: {Inertial, Regular, Intra-assignment}
Table Of Contents Copyright © 2020 Maven Silicon 17
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
4.5.2 Wait
4.5.3 Event based timing
Table Of Contents Copyright © 2020 Maven Silicon 18
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
4.6 Procedural blocks
4.6.1 Sequential blocks
4.6.2 Parallel blocks
4.6.3 Named blocks
Table Of Contents Copyright © 2020 Maven Silicon 19
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
4.6.4 Disable
4.6.5 Branching constructs: {if else, case}
Table Of Contents Copyright © 2020 Maven Silicon 20
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
4.6.6 Looping constructs: {for, while, repeat, forever}
Table Of Contents Copyright © 2020 Maven Silicon 21
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
Table Of Contents Copyright © 2020 Maven Silicon 22
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
System tasks & functions
5.1 Display system tasks
5.1.1 $display, $write, $strobe, $monitor
5.2 File operations
5.2.1 File write
Table Of Contents Copyright © 2020 Maven Silicon 23
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
5.2.2 File read
init8x8.txt
5.3 Simulation control system tasks
5.3.1 $finish
5.3.2 $stop
Table Of Contents Copyright © 2020 Maven Silicon 24
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
5.4 Randomizing function
5.4.1 $random
5.5 Command line input function
5.5.1 $test$plusargs
5.6 Simulation time functions
5.6.1 $time
Table Of Contents Copyright © 2020 Maven Silicon 25
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
5.6.2 $realtime
$stime is same as $time but it returns an integer which is 32bits.
Table Of Contents Copyright © 2020 Maven Silicon 26
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
Compiler directives
6.1 `define
6.2 `include
Table Of Contents Copyright © 2020 Maven Silicon 27
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
6.3 `timescale
6.4 `ifdef
Table Of Contents Copyright © 2020 Maven Silicon 28
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
Verilog examples
7.1 One bit full_adder using half_adder
Table Of Contents Copyright © 2020 Maven Silicon 29
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
7.2 2:1 Multiplexer
7.3 4:1 Multiplexer
Table Of Contents Copyright © 2020 Maven Silicon 30
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
7.4 4:2 Priority Encoder
7.5 2:4 decoder
Table Of Contents Copyright © 2020 Maven Silicon 31
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
7.6 ALU
Table Of Contents Copyright © 2020 Maven Silicon 32
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
7.7 DFF-Synchronous reset
7.8 DFF-Asynchronous clear
7.9 Modulo 12 – Counter
Table Of Contents Copyright © 2020 Maven Silicon 33
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
7.10 Dual port synchronous RAM – 256X8
Table Of Contents Copyright © 2020 Maven Silicon 34
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
7.11 Sequence detector-110(Moore overlapping)
Table Of Contents Copyright © 2020 Maven Silicon 35
www.maven-silicon.com