Académique Documents
Professionnel Documents
Culture Documents
overall lexical conventions of Verilog, and how the language defines and interprets various
elements such as white space, strings, numbers, and keywords. Verilog consists of lexical tokens
(one or more characters) of the form:
Comments
Operators
Strings
Numbers
Keywords
Identifiers
Compiler Directives
Identifiers :
Identifiers are names given to objects so that they can be referenced in the design.
Identifiers can start with an alpha character (a-z, A-Z) or an underscore (_).
Data_out
Escaped Identifiers:
Verilog HDL allows any character to be used in an identifier by escaping the identifier. Escaped
identifiers provide a means of including any of the printable ASCII characters in an identifier
(the decimal values 33 through 126, or 21 through 7E in hexadecimal)
Verilog does not allow to identifier to start with a numeric character. So if you really want to use
a identifier to start with a numeric value then use a escape character as shown below.
module \1dff (
q, // Q output
d, // D input
output q, \q~ ;
endmodule
Keywords :
Keywords cannot be used as Identifiers that is module is a keyword but MODULE can be an
Identifier, though it is better not to use them so as to avoid confusion.
Verilog_Keywords:
Comments :
Begin a single-line comment with // and end it with the new- line character.
Begin a multi-line comment with /* and end it with */.
Examples:
Number Specification:
- Sized Numbers
- Un-sized Numbers
Sized Numbers :
Syntax : <size>'<baseformat><number>
Size of the number is calculated in binary format only. If dont mention any size by default it
takes as 32 bit integer .
After this we need to mention the format of number system if it is binary represent as B or b .
If it is decimal represent as D or d .
If it is Octal represent as O or o.
If it is Hexadecimal represent as H or h.
.then write the respective value .
Format : -<size><base><number>
for readability.
Ex :
Ex :
If we going to represent the Negative numbers just put minus sign before size.
Format is -<size><base><number>
If size is smaller than value MSBs of value are truncated with warning (tool dependent)
MSBs of value are filled with zeros. Regardless of MSB being 0 or 1, 0 filling is done
module Verilog_number;
wire status;
Num = 16; // 8b0001_0000
Num = 8b1010_0101;
endmodule
Strengths:
reg,
net,
Nets:
Different types: wire, wand, wor, tri, triand, trior, trireg, etc.
A wire connecting one driver to other gates input. Types wire and tri are identical. Two different
names are used as hint to intent. Type tri implies a tri-state buffer is driving the line.
tri0 - Like tri but when the resultant value is to be Z, it resolves to resistive pulldown.
tri1 - Like tri but when the resultant value is to be Z, it resolves to resistive pullup.
wand (triand) - Type indicates this wire has multiple drivers. (tri-state) The drivers are
configured in a wired-and configuration.
wor (trior) - Type indicates this wire has multiple drivers. (tri-state) The drivers are configured
in a wired-or configuration.
Registers :
Register data types always retain their value until another value is placed on them.
If a reg data type is assigned a value in an always block that has a clock edge expression, a flip-
flop is inferred.
In synthesis, the compiler will generate latches or flip-flops for them. However, if it can be
sure their output does not need to be stored it will synthesize them into wires.
It can be sure they do not have to store if their outputs is based only on their present inputs.
A variable on the Left Hand Side (LHS) of a procedural block assignment is always declared
as a register data type.All other variables are of net type.
Verilog register data types: reg / time / integer / real / realtime / event (reg is the most common
of all.)
A variable is declared of type wire if it appears on the left side ofan continuous assignment
statement.
Structural code continuous assignment statements start with the keyword assign.
Data Types:
Declaration syntax is
integer i, k;
real r;
i = 1;
r = 2.9;
k = r; // k is rounded to 3
Integer :
A general purpose register data type with default value having all x bits.
Differs from reg type as it stores signed quantities as opposed to reg storing unsigned
quantities.
Real Numbers:
When a real value is assigned to an integer, the real number is rounded off to the nearest
integer.
time A special register data type used mainly to store simulation time.
time is an unsigned 64-bit by default. Usually, it is used to store the simulation time.
real time is similar to time except that it has initial value of 0.
Depending upon the timescale specified, real time provides the simulation time with the
fractional part with given precision.