Digital Design Using Verilog -For Absolute Beginners
LECTURE5 : VERILOG DATA TYPES
•Verilog is a powerful HDL used to design & verify
the digital systems.
•So, to describe the hardware of a system several
types of data variables are required.
•For ex; to describe a signal, its type must be
specified , like bit type , which means that the signal
can have only either 0 or 1, or type std _ logic, in
which the signal can be assigned a value out of four
possible values which include 0, 1, unknown(x) and
high impedance (z) .
• There are two important data types: (i).the variable
data types and (ii). net data types.
• These two groups differ in the way that they are
assigned and hold values.They also represent
different hardware structures.
• The net data types shall represent physical
connections between structural entities, such as
• A net shall not store a value (except for the trireg
net). Instead, its value shall be determined by the
values of its drivers, such as a continuous
assignment or a gate.21 June 2020 email@example.com
Declaration of ‘net’
• Nets are declared by the predefined word ‘wire’.
Nets have values that change continuously by the
circuits that are driving them.
• Verilog supports four values for nets. They are
21 June 2020 firstname.lastname@example.org
• Examples of net types are
wire S1 = 1’b0; similarly wire S2= 4’b0101
• The second statement declares a net by the name
• The third statement declares a net by the name of
S1 ; its initial value is 1’b0, which represents 1 bit
with value 0.
• Similarly ,initial value of S2 is 4 bit with value 0101
21 June 2020 email@example.com
• A wire does not store its value. It must be driven in
one of two ways:
(i).By connecting the wire to the output of a gate or
(ii).By assigning a value to the wire in a continuous
wire y :
assign y = a & b;
21 June 2020 firstname.lastname@example.org
• By default Nets are 1-bit values. But it can be a
• For ex: wire [31:0]bus ; Here the size of the bus is
32 bit vector and it is a wire type.
• All unconnected nets are set to ‘z’.(High impedance)
• Also wire is always input , for standard
• Nets are used to model connections between
continuous assignments and instantiations.
21 June 2020 email@example.com
//internal variable declarations
endmodule21 June 2020 firstname.lastname@example.org
• In the example, S, A1,B1 are declared as Wire.
• Because they denote the interconnections and they
are continuously driven by NOT,AND1 and AND2
• By default they assume bit values.(either o or 1).
21 June 2020 email@example.com
Different Net Types
• Verilog supports different net types for synthesis.
ii. wor (wired or)
iii.Wand (wired and)
• Here wire and Tri state serve the same purpose.
21 June 2020 firstname.lastname@example.org
• The net types wire and tri shall be identical in their
syntax and functions;
• Two names are provided so that the name of a net
can indicate the purpose of the net in that model.
• A wire net can be used for nets that are driven by a
single gate or continuous assignment.
• The tri net type can be used where multiple drivers
drive a net..
21 June 2020 email@example.com
Different Types of Nets.
• wor /wand inserts an or/and gate at the connection as
• Suppose we have a connection shown below.
• The simulator will give an error .
• So, if we use wand (wired and)
the synthesis tool during synthesis
will add an add gate as shown below.
Similarly ,if wor is used an or gate is added at the
connection,which solves the conflict.
• s.21 June 2020 firstname.lastname@example.org
Different Net Types
• wired and(wand circuit) wired or (wor circuit)
21 June 2020 email@example.com
Ex: Supply 0 & Supply1
21 June 2020 firstname.lastname@example.org
• Normally, the during the synthesis, the tool will
consider Supply0 as ground and Supply1 as Vdd.
• Let us consider an example.
21 June 2020 email@example.com
So, the tool during the synthesis, will treat the
supply0 as ground and Supply1 as Vdd.
• Register, in contrast to nets, stores values until they
are updated. Register, as its name suggests,
represents data-storage elements. Register is
declared by the predefined word reg.
• Verilog supports four values shown below, for
21 June 2020 firstname.lastname@example.org
• Different register types are supported by Verilog for
• Reg (register)
• General rule of thumb is,reg is used to model actual
hardware registers such as Counters, Accumulators
• Integer is used for situations like loop counting.
• By default the size of the register is bit
• Ex: reg x,y21 June 2020 email@example.com
• Vectors are multiple bits. A register or a net can be
declared as a vector.
• Vectors are declared by brackets [ ].
• Examples of vectors are:
• wire [31:0] a = 32’b1010;
• reg [7:0] total = 8’d12;
• The first statement declares a net a. It has 32 bits,
and its initial value is 00…1010 (b stands for bit).
The second statement declares a register total.
• Its size is eight bits, and its value is decimal 12 (d
stands for decimal).21 June 2020 firstname.lastname@example.org
• Floating point values are denoted by Real.
• These Real (floating-point) numbers are declared
with the predefined word ‘ real ‘.
• Examples of real values are 2.4, 56.3, and 5e12 (
• The value 5e12 is equal to 5 × 1012.
• The following statement declares the register weight
• real weight;
21 June 2020 email@example.com
• A parameter represents constant value symbolically.
• The definition for a parameter consists of the
parameter name and the value assigned to it.
• The value can be any constant-valued integer or
• If you do not set the size of the parameter with a
range definition or a sized constant, the parameter
is unsized and by default it is a 32-bit quantity
21 June 2020 firstname.lastname@example.org
module my_comp1 (X, Y, xgty, xlty, xeqy);
parameter N = 3;
input [N:0] X, Y;
output xgty, xlty, xeqy;
wire [N:0] sum, Y;
To change the size of the inputs x and y, the size of
the nets sum, and the size of net Y to eight bits, the
value of N is changed to seven as:
• parameter N = 7
21 June 2020 email@example.com
Verilog, in contrast to VHDL, does not have a predefined
word for array.
• Registers and integers can be written as arrays. For
• parameter N = 4;
• parameter M = 3;
• reg signed [M:0] carry [0:N];
• The above statements declare an array by the name
carry. The array carry has five elements, and each
element is four bits. The four bits are in two’s
complement form. For example, if the value of a certain
element is 1001, then it is equivalent to decimal –7.21 June 2020 firstname.lastname@example.org
21 June 2020 email@example.com
• A time variable is used for storing and
manipulating simulation time quantities in
situations where timing checks are required and
for diagnostics and debugging purposes.
• This data type is typically used in conjunction
with the $time system function.
21 June 2020 firstname.lastname@example.org
• An integer is a general-purpose variable used for
manipulating quantities that are not regarded as
hardware registers i.e for loops-indicies,
parameters, and constants.
• They are of implicitly of type reg. However they
store data as signed numbers whereas explicitly
declared reg types store them as unsigned.
• The default size of Integer is 32-bits.
• If they hold constants, the synthesis tool will
adjusts them to the minimum width needed at
• An integer declaration uses the integer keyword and
specifies a list of variables.
• integer a, b; //two integers
• integer c [1:10]; // an array of integers.
• integer data; // integer
• integer i, j, k; // multiple integers
• An integer is a general purpose 32-bit variable.
Operations on it are assumed to be two's
complement and the most significant bit indicates
21 June 2020 email@example.com
Offenbar haben Sie einen Ad-Blocker installiert. Wenn Sie SlideShare auf die Whitelist für Ihren Werbeblocker setzen, helfen Sie unserer Gemeinschaft von Inhaltserstellern.
Sie hassen Werbung?
Wir haben unsere Datenschutzbestimmungen aktualisiert.
Wir haben unsere Datenschutzbestimmungen aktualisiert, um den neuen globalen Regeln zum Thema Datenschutzbestimmungen gerecht zu werden und dir einen Einblick in die begrenzten Möglichkeiten zu geben, wie wir deine Daten nutzen.
Die Einzelheiten findest du unten. Indem du sie akzeptierst, erklärst du dich mit den aktualisierten Datenschutzbestimmungen einverstanden.