2.VLSI Design Using Verilog HDL 2.1 Explain The Steps Involved in The Design Flow For The VLSI IC Design: Typical Design Flow
2.VLSI Design Using Verilog HDL 2.1 Explain The Steps Involved in The Design Flow For The VLSI IC Design: Typical Design Flow
2.VLSI Design Using Verilog HDL 2.1 Explain The Steps Involved in The Design Flow For The VLSI IC Design: Typical Design Flow
Inputs
Internally, input ports must always be of the type net. Externally, the inputs can be connected to a variable
which is a reg or a net.
Outputs
Internally, outputs ports can be of the type reg or net. Externally, outputs must always be connected to a net. They
cannot be connected to a reg.
Inouts
Internally, inout ports must always be of the type net. Externally, inout ports must always be connected to a net.
Width matching
It is legal to connect internal and external items of different sizes when making inter-module port connections.
However, a warning is typically issued that the widths do not match.
Unconnected ports
Verilog allows ports to remain unconnected. For example, certain output ports might be simply for debugging, and
you might not be interested in connecting them to the external signals. You can let a port remain unconnected by
instantiating a module as shown below.
fulladd4 fa0(SUM, , A, B, C_IN); // Output port c_out is unconnected
Example of illegal port connection
To illustrate port connection rules, assume that the module fulladd4 in Example is instantiated in the stimulus
block Top. Example shows an illegal port connection.
Example Illegal Port Connection
module Top;
//Declare connection variables
reg [3:0]A,B;
reg C_IN;
reg [3:0] SUM;
wire C_OUT;
//Instantiate fulladd4, call it fa0
fulladd4 fa0(SUM, C_OUT, A, B, C_IN);
//Illegal connection because output port sum in module fulladd4 //is connected to a register variable
SUM in module Top.
.
.
<stimulus>
.
endmodule
This problem is rectified if the variable SUM is declared as a net (wire).
2.10 Explain the lexical conventions like number specification,identifiers keywords,etc:
Lexical Conventions
The basic lexical conventions used by Verilog HDL are similar to those in the C programming language. Verilog
contains a stream of tokens. Tokens can be comments, delimiters, numbers, strings, identifiers, and keywords.
Verilog HDL is a case-sensitive language. All keywords are in lowercase.
1. Whitespace:
Blank spaces (\b) , tabs (\t) and newlines (\n) comprise the whitespace. Whitespace is ignored by Verilog except when
it separates tokens. Whitespace is not ignored in strings.
2 Comments:
Comments can be inserted in the code for readability and documentation. There are two ways to write comments. A
one-line comment starts with "//". Verilog skips from that point to the end of line. A multiple-line comment starts
with "/*" and ends with "*/". Multiple-line comments cannot be nested. However, one-line comments can be
embedded in multiple-line comments.
a = b && c; // This is a one-line comment
/* This is a multiple line comment */
/* This is /* an illegal */ comment */
/* This is //a legal comment */
3. Operators
Operators are of three types: unary, binary, and ternary. Unary operators precede the operand. Binary operators
appear between two operands. Ternary operators have two separate operators that separate three operands.
a = ~ b; // ~ is a unary operator. b is the operand
a = b && c; // && is a binary operator. b and c are operands
a = b ? c : d; // ?: is a ternary operator. b, c and d are operands
4. Number Specification
There are two types of number specification in Verilog: sized and unsized.
Sized numbers
Sized numbers are represented as <size> '<base format><number>.
<size> is written only in decimal and specifies the number of bits in the number. Legal base formats are decimal ('d or
'D), hexadecimal ('h or 'H), binary ('b or 'B) and octal ('o or 'O). The number is specified as consecutive digits from 0,
1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f. Only a subset of these digits is legal for a particular base. Uppercase letters are
legal for number specification.
4'b1111 // This is a 4-bit binary number
12'habc //This is a 12-bit hexadecimal number
16'd255 //This is a 16-bit decimal number.
Unsized numbers
Numbers that are specified without a <base format> specification are decimal numbers by default. Numbers that are
written without a <size> specification have a default number of bits that is simulator- and machine-specific (must be at
least 32).
23456 // This is a 32-bit decimal number by default
'hc3 // This is a 32-bit hexadecimal number
'o21 // This is a 32-bit octal number
X or Z values:
Verilog has two symbols for unknown and high impedance values. These values are very important for modeling real
circuits. An unknown value is denoted by an x. A high impedance value is denoted by z.
12'h13x // This is a 12-bit hex number; 4 least significant bits unknown
6'hx // This is a 6-bit hex number
32'bz // This is a 32-bit high impedance number
An x or z sets four bits for a number in the hexadecimal base, three bits for a number in the octal base, and one bit for
a number in the binary base. If the most significant bit of a number is 0, x, or z, the number is automatically extended
to fill the most significant bits, respectively, with 0, x, or z. This makes it easy to assign x or z to whole vector. If the
most significant digit is 1, then it is also zero extended.
Negative numbers
Negative numbers can be specified by putting a minus sign before the size for a constant number. Size constants are
always positive. It is illegal to have a minus sign between <base format> and <number>. An optional signed
specifier can be added for signed arithmetic.
-6'd3 // 8-bitnegative number stored as 2's complement of 3
-6'sd3 // Used for performing signed integer math
4'd-2 // Illegal specification
Underscore characters and question marks
An underscore character "_" is allowed anywhere in a number except the first character. Underscore characters are
allowed only to improve readability of numbers and are ignored by Verilog
A question mark "?" is the Verilog HDL alternative for z in the context of numbers. The ? is used to enhance
readability in the casex and casez statements discussed later , where the high impedance value is a don't care
condition.
12'b1111_0000_1010 // Use of underline characters for readability 4'b10?? //
Equivalent of a 4'b10zz
5. Strings
A string is a sequence of characters that are enclosed by double quotes. The restriction on a string is that it must be
contained on a single line, that is, without a carriage return. It cannot be on multiple lines. Strings are treated as a
sequence of one-byte ASCII values.
"Hello Verilog World" // is a string "a / b" // is a string
6. Identifiers and Keywords:
Keywords are special identifiers reserved to define the language constructs. Keywords are in lowercase. Identifiers
are names given to objects so that they can be referenced in the design. Identifiers are made up of alphanumeric
characters, the underscore ( _ ), or the dollar sign ( $ ). Identifiers are case sensitive. Identifiers start with an
alphabetic character or an underscore. They cannot start with a digit or a $ sign (The $ sign as the first character is
reserved for system tasks)
reg value; // reg is a keyword; value is an identifier
input clk; // input is a keyword, clk is an identifier
7 .Escaped Identifiers:
Escaped identifiers begin with the backslash ( \ ) character and end with whitespace (space, tab, or newline) . All
characters between backslash and whitespace are processed literally. Any printable ASCII character can be included in
escaped identifiers. Neither the backslash nor the terminating whitespace is considered to be a part of the identifier.
\a+b-c
\**my_name**
2.11 explain different data types like value set,nets,registers,vectors,integer,real and time register data
types,arrays,memories and strings:
Data types:
1. Value Set
Verilog supports four values and eight strengths to model the functionality of real hardware. The four value
levels are listed in Table.
Table: Value Levels
Value Level Condition in Hardware Circuits
0 Logic zero, false condition
In addition to logic values, strength levels are often used to resolve conflicts between drivers of different strengths in
digital circuits. Value levels 0 and 1 can have the strength levels listed in Table
Table Strength Levels
If two signals of unequal strengths are driven on a wire, the stronger signal prevails. For example, if two signals of
strength strong1 and weak0 contend, the result is resolved as a strong1. If two signals of equal strengths are driven on
a wire, the result is unknown. If two signals of strength strong1 and strong0 conflict, the result is an x. Strength levels
are particularly useful for accurate modeling of signal contention, MOS devices, dynamic MOS, and other low-level
devices. Only trireg nets can have storage strengths large, medium, and small.
2. Nets
Nets represent connections between hardware elements. Just as in real circuits, nets have values continuously driven
on them by the outputs of devices that they are connected to. In Figure 3-1 net a is connected to the output of and gate
g1. Net a will continuously assume the value computed at the output of gate g1, which is b & c.
Figure Example of Nets
Nets are declared primarily with the keyword wire. Nets are one-bit values by default unless they are declared
explicitly as vectors. The terms wire and net are often used interchangeably. The default value of a net is z (except the
trireg net, which defaults to x ). Nets get the output value of their drivers. If a net has no driver, it gets the value z.
\n newline
\t tab
%% %
\\ \
\" "
Format Display
%d or %D Display variable in decimal
%v or %V Display strength
Exampleshows some examples of the $display task. If variables contain x or zvalues, they are printed in the
displayed string as "x" or "z".
Example :$display Task
//Display the string in quotes
$display("Hello Verilog World");
-- Hello Verilog World
//Display value of current simulation time 230
$display($time);
-- 230
//Display value of 41-bit virtual address 1fe0000001c at time 200
reg [0:40] virtual_addr;
$display("At time %d virtual address is %h", $time, virtual_addr);
-- At time 200 virtual address is 1fe0000001c
//Display value of port_id 5 in binary reg [4:0] port_id;
$display("ID of the port is %b", port_id);
-- ID of the port is 00101
//Display x characters
//Display value of 4-bit bus 10xx (signal contention) in binary
reg [3:0] bus;
$display("Bus value is %b", bus);
-- Bus value is 10xx
//Display the hierarchical name of instance p1 instantiated under
//the highest-level module called top. No argument is required. This
//is a useful feature)
$display("This string is displayed from %m level of hierarchy");
-- This string is displayed from top.p1 level of hierarchy
Examples of displaying special characters in strings as discussed are shown in Example 3-4.
Example : Special Characters
//Display special characters, newline and %
$display("This is a \n multiline string with a %% sign");
This is a
multiline string with a % sign
//Display other special characters
Monitoring informationVerilog provides a mechanism to monitor a signal when its value changes. This facility is
provided by the $monitor task.
Usage: $monitor(p1,p2,p3,....,pn);
The parameters p1, p2, ... , pn can be variables, signal names, or quoted strings. A format similar to the $display task
is used in the $monitor task. $monitor continuously monitors the values of the variables or signals specified in the
parameter list and displays all parameters in the list whenever the value of any one variable or signal changes. Unlike
$display, $monitor needs to be invoked only once.
Only one monitoring list can be active at a time. If there is more than one $ monitor statement in your simulation,
the last $monitor statement will be the active statement. The earlier $monitor statements will be overridden.
Two tasks are used to switch monitoring on and off.
Usage: $monitoron;
$monitoroff;
The $monitoron tasks enables monitoring, and the $monitoroff task disables monitoring during a simulation.
Monitoring is turned on by default at the beginning of the simulation and can be controlled during the simulation with
the $monitoron and $monitoroff tasks. Examples of monitoring statements are given in Example. Note the use of
$time in the $monitor statement.
Example Monitor Statement
//Monitor time and value of the signals clock and reset
//Clock toggles every 5 time units and reset goes down at 10 time units initial
begin
$monitor($time," Value of signals clock = %b reset = %b", clock,reset);
end
Partial output of the monitor statement:
0 Value of signals clock = 0 reset = 1
5 Value of signals clock = 1 reset = 1
10 Value of signals clock = 0 reset = 0
Stopping and finishing in a simulation
The task $stop is provided to stop during a simulation.
Usage: $stop;
The $stop task puts the simulation in an interactive mode. The designer can then debug the design from the interactive
mode. The $stop task is used whenever the designer wants to suspend the simulation and examine the values of signals
in the design.The $finish task terminates the simulation.
` Usage: $finish;
Examples of $stop and $finish are shown in Example
Example Stop and Finish Tasks
// Stop at time 100 in the simulation and examine the results
// Finish the simulation at time 1000.
initial // to be explained later.
time = 0
begin
clock = 0;
reset = 1;
#100 $stop; // This will suspend the simulation at time = 100
#900 $finish; // This will terminate the simulation at time = 1000
end
Compiler Directives
Compiler directives are provided in Verilog. All compiler directives are defined by using the `<keyword> construct.
We deal with the two most useful compiler directives.
`define
The `define directive is used to define text macros in Verilog Example. The Verilog compiler substitutes the text of
the macro wherever it encounters a `<macro_name>. This is similar to the #define construct in C. The defined
constants or text macros are used in the Verilog code by preceding them with a ` (back tick).
Example `define Directive
//define a text macro that defines default word size //Used as 'WORD_SIZE in the code
'define WORD_SIZE 32
//define an alias. A $stop will be substituted wherever 'S appears
'define S $stop;
//define a frequently used text string
'define WORD_REG reg [31:0]
// you can then define a 32-bit register as 'WORD_REG reg32;
`include
The `include directive allows you to include entire contents of a Verilog source file in another Verilog file during
compilation. This works similarly to the #include in the C programming language. This directive is typically used
to include header files, which typically contain global or commonly used definitions (see Example .
Example `include Directive
Include the file header.v, which contains declarations in the
main verilog file design.v.
'include header.v
...
...
<Verilog code in file design.v>
...
...
Two other directives, `ifdef and `timescale, are used frequently.
2.14 Define expression ,operators and oparends:
Expressions
Expressions are constructs that combine operators and operands to produce a result.
% modulus two
** power (exponent) two
Unary operators
The operators + and - can also work as unary operators. They are used to specify the positive or negative sign of the
operand. Unary + or ? operators have higher precedence than the binary + or ? operators.
-4 // Negative 4 +5 // Positive 5
Negative numbers are represented as 2's complement internally in Verilog. It is advisable to use negative numbers
only of the type integer or real in expressions. Designers should avoid negative numbers of the type <sss>
'<base><nnn> in expressions because they are converted to unsigned 2's complement numbers and hence yield
unexpected results.
//Advisable to use integer or real numbers -10 / 5// Evaluates to -2
//Do not use numbers of type <sss> '<base><nnn>
-'d10 / 5// Is equivalent (2's complement of 10)/5 = (232 - 10)/5
//where 32 is the default machine word width.
//This evaluates to an incorrect and unexpected result
~ bitwise negation one
& bitwise and two
Bitwise | bitwise or two
^ bitwise xor two
^~ or ~^ bitwise xnor two
2. Logical Operators
Logical operators are logical-and (&&), logical-or (||) and logical- not (!). Operators && and || are binary operators.
Operator ! is a unary operator. Logical operators follow these conditions:
1.Logical operators always evaluate to a 1-bit value, 0 (false), 1 (true), or x (ambiguous).
2.If an operand is not equal to zero, it is equivalent to a logical 1 (true condition). If it is 01equal to zero, it is
equivalent to a logical 0 (false condition). If any operand bit is x or z, it is equivalent to x (ambiguous condition) and
is normally treated by simulators as a false condition.
3. Logical operators take variables or expressions as operands.Use of parentheses to group logical operations is
highly recommended to improve readability. Also, the user does not have to remember the precedence of operators.
Logical operations A = 3; B = 0;
A && B // Evaluates to 0. Equivalent to (logical-1 && logical-0)
A || B // Evaluates to 1. Equivalent to (logical-1 || logical-0)
!A// Evaluates to 0. Equivalent to not(logical-1)
!B// Evaluates to 1. Equivalent to not(logical-0)
//Unknowns
A = 2'b0x; B = 2'b10;
A && B // Evaluates to x. Equivalent to (x && logical 1)
// Expressions
(a == 2) && (b == 3) // Evaluates to 1 if both a == 2 and b == 3 are true.
// Evaluates to 0 if either is false.
3 .Relational Operators
Relational operators are greater-than (>), less-than (<), greater-than-or-equal-to (>=), and less-than-or-equal-to (<=).
If relational operators are used in an expression, the expression returns a logical value of 1 if the expression is true and
0 if the expression is false. If there are any unknown or z bits in the operands, the expression takes a value x. These
operators function exactly as the corresponding operators in the C programming language.
//A = 4, B = 3
//X = 4'b1010, Y = 4'b1101,
//Z = 4'b1xxx
A <= B // Evaluates to a logical 0
A > B // Evaluates to a logical 1
Y >= X // Evaluates to a logical 1
Y < Z // Evaluates to an x
4. Equality Operators
Equality operators are logical equality (==), logical inequality (!=), case equality (===), and case inequality (!==) .
When used in an expression, equality operators return logical value 1 if true, 0 if false. These operators compare the
two operands bit by bit, with zero filling if the operands are of unequal length. Table lists the operators
Table Equality Operators
Possible Logical
Expression Description
Value
It is important to note the difference between the logical equality operators (==, !=) and case equality operators (===, !
==). The logical equality operators (==, !=) will yield an x if either operand has x or z in its bits. However, the case
equality operators ( ===, !== ) compare both operands bit by bit and compare all bits, including x and z. The result is
1 if the operands match exactly, including x and z bits. The result is 0 if the operands do not match exactly. Case
equality operators never result in an x.
//A = 4, B = 3
//X = 4'b1010, Y = 4'b1101
//Z = 4'b1xxz, M = 4'b1xxz, N = 4'b1xxx
A == B // Results in logical 0
X != Y // Results in logical 1
5. Bitwise Operators
Bitwise operators are negation (~), and(&), or (|), xor (^), xnor (^~, ~^). Bitwise operators perform a bit-by-bit
operation on two operands. They take each bit in one operand and perform the operation with the corresponding bit in
the other operand. If one operand is shorter than the other, it will be bit-extended with zeros to match the length of the
longer operand. Logic tables for the bit-by-bit computation are shown in Table A z is treated as an x in a bitwise
operation. The exception is the unary negation operator (~), which takes only one operand and operates on the bits of
the single operand.
Table . Truth Tables for Bitwise Operators