SlideShare a Scribd company logo
ENGR. RASHID FARID CHISHTI
LECTURER,DEE, FET, IIUI
CHISHTI@IIU.EDU.PK
WEEK 5
VERILOG PROGRAMMING
FPGA Based System Design
Sunday, May 17, 2015
1
www.iiu.edu.pk
www.iiu.edu.pk Sunday, May 17, 2015
module half_adder(s,c,a,b);
input a,b;
output s,c;
xor (s,a,b);
and (c,a,b);
endmodule
module full_adder(S,Co,A,B,Ci);
input A,B,Ci;
output S,Co; wire w1,w2,w3;
half_adder h1(w1,w2,A,B);//instantiate from half
adder
half_adder h2(S,w3,w1,Ci);
or (Co,w2,w3);
Gate Level Modeling
2
w3
w1
w2
www.iiu.edu.pk Sunday, May 17, 2015
module four_bit_adder(Sum,Cout,A,B,Cin);
// I/O port declarations
output [3:0] Sum; output Cout;
input[3:0] A, B; input Cin;
wire c1, c2, c3; // Internal nets
// Instantiate four 1-bit full adders.
full_adder FA0(Sum[0], c1, A[0], B[0], Cin);
full_adder FA1(Sum[1], c2, A[1], B[1], c1);
full_adder FA2(Sum[2], c3, A[2], B[2], c2);
full_adder FA3(Sum[3], Cout, A[3], B[3], c3);
endmodule
4-Bit Full Adder instantiating from 1-bit full adder
3
A module provides a template from which you can create actual
objects.
When a module is invoked, Verilog creates a unique object from the
template.
Each object has its own name, variables, parameters, and I/O
interface.
The process of creating objects from a module template is called
instantiation, and the objects are called instances
In four_bit_adder module we used 4 instances of full_adder
template and each instance has been given a unique name.
Illegal Module Nesting
module full_adder(S,Co,A,B,Ci);
input A,B,Ci; output S,Co;
module half_adder(S,Co,A,B); // Illegal module nesting
endmodule // End of Illegal nesting
endmodule
Module Instantiation
Sunday, May 17, 2015www.iiu.edu.pk 4
www.iiu.edu.pk Sunday, May 17, 2015
Design Hierarchy
5
1-bit Full Adder1-bit Full Adder 1-bit Full Adder1-bit Full Adder 1-bit Full Adder1-bit Full Adder
Half AdderHalf Adder OROR
ANDAND XORXOR
Four Bit Full AdderFour Bit Full Adder
1-bit Full Adder1-bit Full Adder
Half AdderHalf Adder
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 */
Operators
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
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.
9'O641 // This is a 12-bit octal number
// Uppercase letters (B,H,D,O) are also legal for number specification.
www.iiu.edu.pk Sunday, May 17, 2015
Lexical Conventions in Verilog
6
Unsized numbers
Numbers that are specified without a <base format> specification are
decimal numbers by default.
Numbers that are written without a <size> specification are 32 bit.
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
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, orwww.iiu.edu.pk Sunday, May 17, 2015
Lexical Conventions in Verilog (2)
7
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
-6'd3 // 6-bit negative 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.
12'b1111_0000_1010 // Use of underline characters for readability
4'b10?? // Equivalent of a 4'b10zz
www.iiu.edu.pk Sunday, May 17, 2015
Lexical Conventions in Verilog (3)
8
 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
 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 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 e.g. $monitor ).
reg value; // reg is a keyword; value is an identifier
input clk; // input is a keyword, clk is an identifier
www.iiu.edu.pk Sunday, May 17, 2015
Lexical Conventions in Verilog (4)
9
 Escaped Identifiers List of Keywords
 Escaped identifiers begin
with the backslash (  )
character and end with
whitespace (space, tab, or
newline).
 All characters between
backslash and whitespace
are processed literally.
 Neither the backslash nor the
terminating whitespace is
considered to be a part of the
identifier.
a+b-c **my_name**
www.iiu.edu.pk Sunday, May 17, 2015
Lexical Conventions in Verilog (5)
10
always
and
assign
attribute
begin
buf
bufif0
bufif1
case
casex
casez
cmos
deassign
default
defparam
disable
edge
else
end
endattribute
endcase
endfunction
endmodule
endprimitive
endspecify
endtable
endtask
event
for
force
forever
fork
function
highz0
highz1
if
ifnone
initial
inout
input
integer
join
medium
module
large
macromodule
nand
negedge
nmos
nor
not
notif0
notif1
or
output
parameter
pmos
posedge
primitive
pull0
pull1
pulldown
pullup
rcmos
real
realtime
reg
release
repeat
rnmos
rpmos
rtran
rtranif0
rtranif1
scalared
signed
small
specify
specparam
strength
strong0
strong1
supply0
supply1
table
task
time
tran
tranif0
tranif1
tri
tri0
tri1
triand
trior
trireg
unsigned
vectored
wait
wand
weak0
weak1
while
wire
wor
xnor
xor
 List of Keywords Value Set
 Verilog supports four values and eight strengths to model the functionality of real
hardware. The four value levels are:
Value Level Condition in Hardware Circuits
0 Logic zero, false condition
1 Logic one, true condition
x Unknown logic value
z High impedance, floating state
 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 following strength levels
Strength Level Type Degree
supply Driving strongest
strong Driving
pull Driving
large Storage
www.iiu.edu.pk Sunday, May 17, 2015
Data Types in Verilog (1)
11
Strength Level Type Degree
weak Driving
medium Storage
small Storage
highz High Impedance weakest
 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.
 For Example; 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.
www.iiu.edu.pk Sunday, May 17, 2015
Data Types in Verilog (2)
12
 Wires or Nets : represents a physical wire in a circuit and is used to connect
gates or modules. A wire does not store its value but must be driven by a
continuous assignment statement or by connecting it to the output of a gate or
module.
 Nets get the output value of their drivers. If a net has no driver, it gets the value z.
wire a; // Declare net a for the above circuit
wire b,c; // Declare two wires b,c for the above circuit
wire d = 1'b0; // Net d is fixed to logic value 0 at declaration.
 Other specific types of wires include:
 wand ( output of a wand is logical AND of all the drivers connected to it.)
 wor (output of wor is logical OR of all the drivers connected to it.)
 tri (to join output of multiple tri state buffers)
wire a,b; wand d; assign d = a; assign d = b; // d is logical and of a and b
www.iiu.edu.pk Sunday, May 17, 2015
Data Types in Verilog (3)
13
 Registers: A reg is a Verilog variable type and does not necessarily imply a
physical register. In multi-bit registers, data is stored as unsigned numbers and no
sign extension is done for what the user might have thought were two’s
complement numbers.
 Unlike a net, a register does not need a driver. Values of registers can be changed
anytime in a simulation by assigning a new value to the register.
 The default value for a reg data type is x.
reg reset; // declare a variable reset that can hold its value
initial // this construct will be discussed later
begin
reset = 1'b1; // initialize reset to 1 to reset the digital circuit.
#100 reset = 1'b0; // after 100 time units reset is deasserted.
end
 Registers can also be declared as signed variables. Such registers can be used for
signed arithmetic for example.
reg signed [63:0] m; // 64 bit signed value integer i; // 32 bit signed value .
www.iiu.edu.pk Sunday, May 17, 2015
Data Types in Verilog (4)
14
 Vectors: Nets or reg data types can be declared as vectors (multiple bit widths).
If bit width is not specified, the default is scalar (1-bit).
wire a; // scalar net variable, default
reg [7:0] PortA; // 8-bit Program Counter Register
reg [31:0] ACC, AR , IR; // 3 registers
reg clock; // scalar register, default
reg [0:40] abs_addr; // Vector register, absolute address 41 bits wide
 Vectors can be declared at [high# : low#] or [low# : high#], but the left number in
the squared brackets is always the most significant bit of the vector. In the
example shown above, bit 0 is the most significant bit of vector virtual_addr.
 Vector Part Select: it possible to address bits or parts of vectors.
initial begin PortA[7] =1'b1; // bit # 7 of vector
AR[2:0]=3'b1zx; // Three least significant bits of Address Register,
// using AR[0:2] is illegal. the significant bit should
// always be on the left of a range specification
abs_addr[0:1] =2'b11; end // Two most significant bits of vector virtual_addr
www.iiu.edu.pk Sunday, May 17, 2015
Data Types in Verilog (5)
15
 Variable Vector Part Select
Another ability provided in Verilog HDl is to have variable part selects of a
vector. This allows part selects to be put in for loops to select various parts of the
vector. There are two special part-select operators:
[<starting_bit>+:width] - part-select increments from starting bit
[<starting_bit>-:width] - part-select decrements from starting bit
The starting bit of the part select can be varied, but the width has to be constant.
reg [255:0] data1; // Little endian notation
reg [0:255] data2; // Big endian notation
reg [7:0] byte, j; // Using a variable part select, one can choose parts
initial begin byte = data1[31-:8]; // starting bit = 31, width =8 => data[31:24]
byte = data1[24+:8]; // starting bit = 24, width =8 => data[31:24]
byte = data2[31-:8]; // starting bit = 31, width =8 => data[24:31]
byte = data2[24+:8]; end// starting bit = 24, width =8 => data[24:31]
// The starting bit can also be a variable. The width has to be constant. Therefore,
// one can use the variable part select in a loop to select all bytes of the vector.
www.iiu.edu.pk Sunday, May 17, 2015
Data Types in Verilog (6)
16
for (j=0; j<=31; j=j+1)
byte = data1[(j*8)+:8]; // Sequence is [7:0], [15:8]... [255:248]
// Can initialize a part of the vector
data1[(byteNum*8)+:8] = 8'b0; // If byteNum = 1, clear 8 bits [15:8]
 Integer , Real, and Time Register Data Types
integer, real, and time register data types are supported in Verilog.
 Integer: An integer is a general purpose register data type used for manipulating
quantities. Integers are declared by the keyword integer. Although it is possible
to use reg as a general-purpose variable, it is more convenient to declare an
integer variable for purposes such as counting. The default width for an integer
is the host-machine word size, which is implementation-specific but is at least 32
bits. Registers declared as data type reg store values as unsigned quantities,
whereas integers store values as signed quantities.
integer counter; // general purpose variable used as a counter.
initial counter = -1; // A negative one is stored in the counter
www.iiu.edu.pk Sunday, May 17, 2015
Data Types in Verilog (7)
17
 Real: Real number constants and real register data types are declared with the
keyword real. They can be specified in decimal notation (e.g., 3.14) or in
scientific notation (e.g., 3e6, which is 3 x 106
). Real numbers cannot have a
range declaration, and their default value is 0. When a real value is assigned to
an integer, the real number is rounded off to the nearest integer.
real delta; // Define a real variable called delta
initial
begin
delta = 4e10; // delta is assigned in scientific notation
delta = 2.13; // delta is assigned a value 2.13
end
integer i; // Define an integer i
initial
i = delta; // i gets the value 2 (rounded value of 2.13)
www.iiu.edu.pk Sunday, May 17, 2015
Data Types in Verilog (8)
18
 Time: Verilog simulation is done with respect to simulation time. A special time
register data type is used in Verilog to store simulation time. A time variable is
declared with the keyword time. The width for time register data types is
implementation-specific but is at least 64 bits.The system function $time is
invoked to get the current simulation time.
time save_sim_time; // Define a time variable save_sim_time
initial save_sim_time = $time; // Save the current simulation time
 Arrays: single and multi dimensional arrays can be made in verilog.
Arrays are accessed by <array_name>[<subscript>]. For multi-dimensional
arrays, indexes need to be provided for each dimension.
integer count[0:7]; // An array of 8 count variables
reg bool[31:0]; // Array of 32 one-bit boolean register variables
time chk_point[1:100]; // Array of 100 time checkpoint variables
reg [4:0] port_id[0:7]; // Array of 8 port_ids; each port_id is 5 bits wide
integer matrix[4:0][0:255]; // Two dimensional array of integers
www.iiu.edu.pk Sunday, May 17, 2015
Data Types in Verilog (9)
19
reg [63:0] array_4d [15:0][7:0][7:0][255:0]; // Four dimensional array
wire [7:0] w_array2 [5:0]; // Declare an array of 8 bit vector wire
wire w_array1[7:0][5:0]; // Declare an array of single bit wires
It is important not to confuse arrays with net or register vectors.
A vector is a single element that is n-bits wide.
On the other hand, arrays are multiple elements that are 1-bit or n-bits wide.
count[5] = 0; // Reset 5th element of array of count variables
chk_point[100] = 0; // Reset 100th time check point value
port_id[3] = 0; // Reset 3rd element (a 5-bit value) of port_id array.
matrix[1][0] = 33559; // Set value of element indexed by [1][0] to 33559
array_4d[0][0][0][0][15:0] = 0; // Clear bits 15:0 of the register
// accessed by indices [0][0][0][0]
port_id = 0; // Illegal syntax - Attempt to
www.iiu.edu.pk Sunday, May 17, 2015
Data Types in Verilog (10)
20
write the entire array
matrix [1] = 0; // Illegal syntax - Attempt to write [1][0]..[1]
[255]
 Memories: In digital simulation, one often needs to model register files, RAMs,
and ROMs. Memories are modeled in Verilog simply as a one-dimensional array
of registers. Each element of the array is known as an element or word and is
addressed by a single array index. Each word can be one or more bits. It is
important to differentiate between n 1-bit registers and one n-bit register.
reg mem1bit[0:1023]; // Memory mem1bit with 1K 1-bit words reg [7:0]
membyte[0:1023]; // Memory membyte with 1K 8-bit words(bytes)
membyte[511] // Fetches 1 byte word whose address is 511
reg [7:0] RAM1 [15:0]; // 16 Bytes RAM
reg [15:0] RAM2[2047:0]; // 2K Words RAM
www.iiu.edu.pk Sunday, May 17, 2015
Data Types in Verilog (11)
21
Ad

More Related Content

What's hot (20)

Basic concepts in Verilog HDL
Basic concepts in Verilog HDLBasic concepts in Verilog HDL
Basic concepts in Verilog HDL
anand hd
 
Unit v. HDL Synthesis Process
Unit v. HDL Synthesis ProcessUnit v. HDL Synthesis Process
Unit v. HDL Synthesis Process
Principal,Guru Nanak Institute of Technology, Nagpur
 
Half adder layout design
Half adder layout designHalf adder layout design
Half adder layout design
Thevenin Norton TOng
 
Design and implementation of 32 bit alu using verilog
Design and implementation of 32 bit alu using verilogDesign and implementation of 32 bit alu using verilog
Design and implementation of 32 bit alu using verilog
STEPHEN MOIRANGTHEM
 
How to create SystemVerilog verification environment?
How to create SystemVerilog verification environment?How to create SystemVerilog verification environment?
How to create SystemVerilog verification environment?
Sameh El-Ashry
 
Apb
ApbApb
Apb
Azad Mishra
 
Unit VI CPLD-FPGA Architecture
Unit VI CPLD-FPGA ArchitectureUnit VI CPLD-FPGA Architecture
Unit VI CPLD-FPGA Architecture
Principal,Guru Nanak Institute of Technology, Nagpur
 
UVM Methodology Tutorial
UVM Methodology TutorialUVM Methodology Tutorial
UVM Methodology Tutorial
Arrow Devices
 
Verilog
VerilogVerilog
Verilog
Mohamed Rayan
 
Session 2,3 FPGAs
Session 2,3 FPGAsSession 2,3 FPGAs
Session 2,3 FPGAs
Subhash Iyer
 
Fpga 04-verilog-programming
Fpga 04-verilog-programmingFpga 04-verilog-programming
Fpga 04-verilog-programming
Malik Tauqir Hasan
 
VLSI lab report using Cadence tool
VLSI lab report using Cadence toolVLSI lab report using Cadence tool
VLSI lab report using Cadence tool
Maharaja Institute of Technology Mysore
 
Lect 7: Verilog Behavioral model for Absolute Beginners
Lect 7: Verilog Behavioral model for Absolute BeginnersLect 7: Verilog Behavioral model for Absolute Beginners
Lect 7: Verilog Behavioral model for Absolute Beginners
Dr.YNM
 
Basic structures in vhdl
Basic structures in vhdlBasic structures in vhdl
Basic structures in vhdl
Raj Mohan
 
Data types in verilog
Data types in verilogData types in verilog
Data types in verilog
Nallapati Anindra
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
mengistu ketema
 
FPGA Introduction
FPGA IntroductionFPGA Introduction
FPGA Introduction
Kamlesh Kumar
 
UVM TUTORIAL;
UVM TUTORIAL;UVM TUTORIAL;
UVM TUTORIAL;
Azad Mishra
 
CSL 202, Adders and Subtractors
CSL 202, Adders and SubtractorsCSL 202, Adders and Subtractors
CSL 202, Adders and Subtractors
CKSunith1
 
axi protocol
axi protocolaxi protocol
axi protocol
Azad Mishra
 

Similar to Fpga 05-verilog-programming (20)

Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adder
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adderFpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adder
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adder
Malik Tauqir Hasan
 
Verilogspk1
Verilogspk1Verilogspk1
Verilogspk1
supriya kurlekar
 
Verilog Final Probe'22.pptx
Verilog Final Probe'22.pptxVerilog Final Probe'22.pptx
Verilog Final Probe'22.pptx
SyedAzim6
 
Verilog HDL
Verilog HDL Verilog HDL
Verilog HDL
HasmukhPKoringa
 
VHDL- data types
VHDL- data typesVHDL- data types
VHDL- data types
VandanaPagar1
 
DDUV.pdf
DDUV.pdfDDUV.pdf
DDUV.pdf
VandanaPagar1
 
very large scale integration ppt vlsi.pptx
very large scale integration ppt vlsi.pptxvery large scale integration ppt vlsi.pptx
very large scale integration ppt vlsi.pptx
nandithad23
 
Experiment 1- UCS 704_ESD engineering money waste
Experiment 1- UCS 704_ESD engineering money wasteExperiment 1- UCS 704_ESD engineering money waste
Experiment 1- UCS 704_ESD engineering money waste
kartikgupta886034
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhts
Béo Tú
 
Module 2 VLSI design and verification by
Module 2 VLSI design and verification byModule 2 VLSI design and verification by
Module 2 VLSI design and verification by
ShravanKumar124460
 
Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
Muhammad Uzair Rasheed
 
C Programming
C ProgrammingC Programming
C Programming
Adil Jafri
 
Chap1 language fondamentale of java ( scjp /ocjp)
Chap1 language fondamentale of java ( scjp /ocjp)Chap1 language fondamentale of java ( scjp /ocjp)
Chap1 language fondamentale of java ( scjp /ocjp)
It Academy
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
princepavan
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
princepavan
 
systemverilog and veriog presentation
systemverilog    and veriog presentationsystemverilog    and veriog presentation
systemverilog and veriog presentation
KhushiV8
 
System Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLSystem Verilog Tutorial - VHDL
System Verilog Tutorial - VHDL
E2MATRIX
 
Verilog Tutorial - Verilog HDL Tutorial with Examples
Verilog Tutorial - Verilog HDL Tutorial with ExamplesVerilog Tutorial - Verilog HDL Tutorial with Examples
Verilog Tutorial - Verilog HDL Tutorial with Examples
E2MATRIX
 
VIT_Workshop.ppt
VIT_Workshop.pptVIT_Workshop.ppt
VIT_Workshop.ppt
VINOTHRAJR1
 
vlsi design using verilog presentaion 1
vlsi design using verilog   presentaion 1vlsi design using verilog   presentaion 1
vlsi design using verilog presentaion 1
MANDHASAIGOUD1
 
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adder
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adderFpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adder
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adder
Malik Tauqir Hasan
 
Verilog Final Probe'22.pptx
Verilog Final Probe'22.pptxVerilog Final Probe'22.pptx
Verilog Final Probe'22.pptx
SyedAzim6
 
very large scale integration ppt vlsi.pptx
very large scale integration ppt vlsi.pptxvery large scale integration ppt vlsi.pptx
very large scale integration ppt vlsi.pptx
nandithad23
 
Experiment 1- UCS 704_ESD engineering money waste
Experiment 1- UCS 704_ESD engineering money wasteExperiment 1- UCS 704_ESD engineering money waste
Experiment 1- UCS 704_ESD engineering money waste
kartikgupta886034
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhts
Béo Tú
 
Module 2 VLSI design and verification by
Module 2 VLSI design and verification byModule 2 VLSI design and verification by
Module 2 VLSI design and verification by
ShravanKumar124460
 
Chap1 language fondamentale of java ( scjp /ocjp)
Chap1 language fondamentale of java ( scjp /ocjp)Chap1 language fondamentale of java ( scjp /ocjp)
Chap1 language fondamentale of java ( scjp /ocjp)
It Academy
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
princepavan
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
princepavan
 
systemverilog and veriog presentation
systemverilog    and veriog presentationsystemverilog    and veriog presentation
systemverilog and veriog presentation
KhushiV8
 
System Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLSystem Verilog Tutorial - VHDL
System Verilog Tutorial - VHDL
E2MATRIX
 
Verilog Tutorial - Verilog HDL Tutorial with Examples
Verilog Tutorial - Verilog HDL Tutorial with ExamplesVerilog Tutorial - Verilog HDL Tutorial with Examples
Verilog Tutorial - Verilog HDL Tutorial with Examples
E2MATRIX
 
VIT_Workshop.ppt
VIT_Workshop.pptVIT_Workshop.ppt
VIT_Workshop.ppt
VINOTHRAJR1
 
vlsi design using verilog presentaion 1
vlsi design using verilog   presentaion 1vlsi design using verilog   presentaion 1
vlsi design using verilog presentaion 1
MANDHASAIGOUD1
 
Ad

More from Malik Tauqir Hasan (10)

Fpga 13-task-and-functions
Fpga 13-task-and-functionsFpga 13-task-and-functions
Fpga 13-task-and-functions
Malik Tauqir Hasan
 
Fpga 12-event-control
Fpga 12-event-controlFpga 12-event-control
Fpga 12-event-control
Malik Tauqir Hasan
 
Fpga 11-sequence-detector-fir-iir-filter
Fpga 11-sequence-detector-fir-iir-filterFpga 11-sequence-detector-fir-iir-filter
Fpga 11-sequence-detector-fir-iir-filter
Malik Tauqir Hasan
 
Fpga 10-bcd-to-excess-3-converter-manchester-encoding
Fpga 10-bcd-to-excess-3-converter-manchester-encodingFpga 10-bcd-to-excess-3-converter-manchester-encoding
Fpga 10-bcd-to-excess-3-converter-manchester-encoding
Malik Tauqir Hasan
 
Fpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machineFpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machine
Malik Tauqir Hasan
 
Fpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineFpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machine
Malik Tauqir Hasan
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directives
Malik Tauqir Hasan
 
Fpga 03-cpld-and-fpga
Fpga 03-cpld-and-fpgaFpga 03-cpld-and-fpga
Fpga 03-cpld-and-fpga
Malik Tauqir Hasan
 
Fpga 02-memory-and-pl ds
Fpga 02-memory-and-pl dsFpga 02-memory-and-pl ds
Fpga 02-memory-and-pl ds
Malik Tauqir Hasan
 
Fpga 01-digital-logic-design
Fpga 01-digital-logic-designFpga 01-digital-logic-design
Fpga 01-digital-logic-design
Malik Tauqir Hasan
 
Fpga 11-sequence-detector-fir-iir-filter
Fpga 11-sequence-detector-fir-iir-filterFpga 11-sequence-detector-fir-iir-filter
Fpga 11-sequence-detector-fir-iir-filter
Malik Tauqir Hasan
 
Fpga 10-bcd-to-excess-3-converter-manchester-encoding
Fpga 10-bcd-to-excess-3-converter-manchester-encodingFpga 10-bcd-to-excess-3-converter-manchester-encoding
Fpga 10-bcd-to-excess-3-converter-manchester-encoding
Malik Tauqir Hasan
 
Fpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machineFpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machine
Malik Tauqir Hasan
 
Fpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineFpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machine
Malik Tauqir Hasan
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directives
Malik Tauqir Hasan
 
Ad

Recently uploaded (20)

Spin_LED_Presentation_Mustaqeem_2025.pptx
Spin_LED_Presentation_Mustaqeem_2025.pptxSpin_LED_Presentation_Mustaqeem_2025.pptx
Spin_LED_Presentation_Mustaqeem_2025.pptx
mustaqeemmujahid
 
Week 2 lecture PCD 203skoacolacbabolabiocasoc
Week 2 lecture PCD 203skoacolacbabolabiocasocWeek 2 lecture PCD 203skoacolacbabolabiocasoc
Week 2 lecture PCD 203skoacolacbabolabiocasoc
saidraqb5
 
Musicfy lolMusicfy lolMusicfy lolMusicfy lol
Musicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lol
Musicfy lolMusicfy lolMusicfy lolMusicfy lol
bilalshah786104
 
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctr
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctrMayur Seminar.pptxbgvyezuvdt as bijvyivutctr
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctr
vaishnavishitole195
 
Unidad Pedagogica 3ro-4to.documento090904
Unidad Pedagogica 3ro-4to.documento090904Unidad Pedagogica 3ro-4to.documento090904
Unidad Pedagogica 3ro-4to.documento090904
maylingcastro9
 
Intro to Windows Presentation for CSS NC-2.pptx
Intro to Windows Presentation for CSS NC-2.pptxIntro to Windows Presentation for CSS NC-2.pptx
Intro to Windows Presentation for CSS NC-2.pptx
HelenAvila17
 
Concavity_Presentation_Updated.pptx rana
Concavity_Presentation_Updated.pptx ranaConcavity_Presentation_Updated.pptx rana
Concavity_Presentation_Updated.pptx rana
ranamumtaz383
 
ideapad_330S_14IKB_Shhjjkjhghhvbhjjjpec.pdf
ideapad_330S_14IKB_Shhjjkjhghhvbhjjjpec.pdfideapad_330S_14IKB_Shhjjkjhghhvbhjjjpec.pdf
ideapad_330S_14IKB_Shhjjkjhghhvbhjjjpec.pdf
MichaelDexterBalanta1
 
Ch 2 The Microprocessor and its Architecture.ppt
Ch 2 The Microprocessor and its Architecture.pptCh 2 The Microprocessor and its Architecture.ppt
Ch 2 The Microprocessor and its Architecture.ppt
ermiasgesgis
 
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptxFeed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
newhopemojokerto90
 
Lecture 1 BASIC TERMINOLOGY of kinematics.ppt
Lecture 1 BASIC TERMINOLOGY of kinematics.pptLecture 1 BASIC TERMINOLOGY of kinematics.ppt
Lecture 1 BASIC TERMINOLOGY of kinematics.ppt
MusniAhmed1
 
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
v65176016
 
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptxCrim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
russelrosas
 
REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682
REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682
REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682
REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682
 
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptxParmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
rahulrajbanshi981052
 
Chapter Five main management of memory .ppt
Chapter Five main management of memory  .pptChapter Five main management of memory  .ppt
Chapter Five main management of memory .ppt
YoomifTube
 
TR INGLES TECNICO ECCU-211 1[mmmm1].pptx
TR INGLES TECNICO ECCU-211 1[mmmm1].pptxTR INGLES TECNICO ECCU-211 1[mmmm1].pptx
TR INGLES TECNICO ECCU-211 1[mmmm1].pptx
EnocngelArcentalesVa
 
JOINING ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON WHATSAPP+256782561496/0756...
JOINING ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON WHATSAPP+256782561496/0756...JOINING ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON WHATSAPP+256782561496/0756...
JOINING ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON WHATSAPP+256782561496/0756...
REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682
 
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdfENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
edget1
 
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdfchapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
edget1
 
Spin_LED_Presentation_Mustaqeem_2025.pptx
Spin_LED_Presentation_Mustaqeem_2025.pptxSpin_LED_Presentation_Mustaqeem_2025.pptx
Spin_LED_Presentation_Mustaqeem_2025.pptx
mustaqeemmujahid
 
Week 2 lecture PCD 203skoacolacbabolabiocasoc
Week 2 lecture PCD 203skoacolacbabolabiocasocWeek 2 lecture PCD 203skoacolacbabolabiocasoc
Week 2 lecture PCD 203skoacolacbabolabiocasoc
saidraqb5
 
Musicfy lolMusicfy lolMusicfy lolMusicfy lol
Musicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lol
Musicfy lolMusicfy lolMusicfy lolMusicfy lol
bilalshah786104
 
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctr
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctrMayur Seminar.pptxbgvyezuvdt as bijvyivutctr
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctr
vaishnavishitole195
 
Unidad Pedagogica 3ro-4to.documento090904
Unidad Pedagogica 3ro-4to.documento090904Unidad Pedagogica 3ro-4to.documento090904
Unidad Pedagogica 3ro-4to.documento090904
maylingcastro9
 
Intro to Windows Presentation for CSS NC-2.pptx
Intro to Windows Presentation for CSS NC-2.pptxIntro to Windows Presentation for CSS NC-2.pptx
Intro to Windows Presentation for CSS NC-2.pptx
HelenAvila17
 
Concavity_Presentation_Updated.pptx rana
Concavity_Presentation_Updated.pptx ranaConcavity_Presentation_Updated.pptx rana
Concavity_Presentation_Updated.pptx rana
ranamumtaz383
 
ideapad_330S_14IKB_Shhjjkjhghhvbhjjjpec.pdf
ideapad_330S_14IKB_Shhjjkjhghhvbhjjjpec.pdfideapad_330S_14IKB_Shhjjkjhghhvbhjjjpec.pdf
ideapad_330S_14IKB_Shhjjkjhghhvbhjjjpec.pdf
MichaelDexterBalanta1
 
Ch 2 The Microprocessor and its Architecture.ppt
Ch 2 The Microprocessor and its Architecture.pptCh 2 The Microprocessor and its Architecture.ppt
Ch 2 The Microprocessor and its Architecture.ppt
ermiasgesgis
 
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptxFeed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
newhopemojokerto90
 
Lecture 1 BASIC TERMINOLOGY of kinematics.ppt
Lecture 1 BASIC TERMINOLOGY of kinematics.pptLecture 1 BASIC TERMINOLOGY of kinematics.ppt
Lecture 1 BASIC TERMINOLOGY of kinematics.ppt
MusniAhmed1
 
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
v65176016
 
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptxCrim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
russelrosas
 
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptxParmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
rahulrajbanshi981052
 
Chapter Five main management of memory .ppt
Chapter Five main management of memory  .pptChapter Five main management of memory  .ppt
Chapter Five main management of memory .ppt
YoomifTube
 
TR INGLES TECNICO ECCU-211 1[mmmm1].pptx
TR INGLES TECNICO ECCU-211 1[mmmm1].pptxTR INGLES TECNICO ECCU-211 1[mmmm1].pptx
TR INGLES TECNICO ECCU-211 1[mmmm1].pptx
EnocngelArcentalesVa
 
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdfENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
edget1
 
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdfchapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
edget1
 

Fpga 05-verilog-programming

  • 1. ENGR. RASHID FARID CHISHTI LECTURER,DEE, FET, IIUI CHISHTI@IIU.EDU.PK WEEK 5 VERILOG PROGRAMMING FPGA Based System Design Sunday, May 17, 2015 1 www.iiu.edu.pk
  • 2. www.iiu.edu.pk Sunday, May 17, 2015 module half_adder(s,c,a,b); input a,b; output s,c; xor (s,a,b); and (c,a,b); endmodule module full_adder(S,Co,A,B,Ci); input A,B,Ci; output S,Co; wire w1,w2,w3; half_adder h1(w1,w2,A,B);//instantiate from half adder half_adder h2(S,w3,w1,Ci); or (Co,w2,w3); Gate Level Modeling 2 w3 w1 w2
  • 3. www.iiu.edu.pk Sunday, May 17, 2015 module four_bit_adder(Sum,Cout,A,B,Cin); // I/O port declarations output [3:0] Sum; output Cout; input[3:0] A, B; input Cin; wire c1, c2, c3; // Internal nets // Instantiate four 1-bit full adders. full_adder FA0(Sum[0], c1, A[0], B[0], Cin); full_adder FA1(Sum[1], c2, A[1], B[1], c1); full_adder FA2(Sum[2], c3, A[2], B[2], c2); full_adder FA3(Sum[3], Cout, A[3], B[3], c3); endmodule 4-Bit Full Adder instantiating from 1-bit full adder 3
  • 4. A module provides a template from which you can create actual objects. When a module is invoked, Verilog creates a unique object from the template. Each object has its own name, variables, parameters, and I/O interface. The process of creating objects from a module template is called instantiation, and the objects are called instances In four_bit_adder module we used 4 instances of full_adder template and each instance has been given a unique name. Illegal Module Nesting module full_adder(S,Co,A,B,Ci); input A,B,Ci; output S,Co; module half_adder(S,Co,A,B); // Illegal module nesting endmodule // End of Illegal nesting endmodule Module Instantiation Sunday, May 17, 2015www.iiu.edu.pk 4
  • 5. www.iiu.edu.pk Sunday, May 17, 2015 Design Hierarchy 5 1-bit Full Adder1-bit Full Adder 1-bit Full Adder1-bit Full Adder 1-bit Full Adder1-bit Full Adder Half AdderHalf Adder OROR ANDAND XORXOR Four Bit Full AdderFour Bit Full Adder 1-bit Full Adder1-bit Full Adder Half AdderHalf Adder
  • 6. 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 */ Operators 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 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. 9'O641 // This is a 12-bit octal number // Uppercase letters (B,H,D,O) are also legal for number specification. www.iiu.edu.pk Sunday, May 17, 2015 Lexical Conventions in Verilog 6
  • 7. Unsized numbers Numbers that are specified without a <base format> specification are decimal numbers by default. Numbers that are written without a <size> specification are 32 bit. 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 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, orwww.iiu.edu.pk Sunday, May 17, 2015 Lexical Conventions in Verilog (2) 7
  • 8. 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 -6'd3 // 6-bit negative 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. 12'b1111_0000_1010 // Use of underline characters for readability 4'b10?? // Equivalent of a 4'b10zz www.iiu.edu.pk Sunday, May 17, 2015 Lexical Conventions in Verilog (3) 8
  • 9.  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  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 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 e.g. $monitor ). reg value; // reg is a keyword; value is an identifier input clk; // input is a keyword, clk is an identifier www.iiu.edu.pk Sunday, May 17, 2015 Lexical Conventions in Verilog (4) 9
  • 10.  Escaped Identifiers List of Keywords  Escaped identifiers begin with the backslash ( ) character and end with whitespace (space, tab, or newline).  All characters between backslash and whitespace are processed literally.  Neither the backslash nor the terminating whitespace is considered to be a part of the identifier. a+b-c **my_name** www.iiu.edu.pk Sunday, May 17, 2015 Lexical Conventions in Verilog (5) 10 always and assign attribute begin buf bufif0 bufif1 case casex casez cmos deassign default defparam disable edge else end endattribute endcase endfunction endmodule endprimitive endspecify endtable endtask event for force forever fork function highz0 highz1 if ifnone initial inout input integer join medium module large macromodule nand negedge nmos nor not notif0 notif1 or output parameter pmos posedge primitive pull0 pull1 pulldown pullup rcmos real realtime reg release repeat rnmos rpmos rtran rtranif0 rtranif1 scalared signed small specify specparam strength strong0 strong1 supply0 supply1 table task time tran tranif0 tranif1 tri tri0 tri1 triand trior trireg unsigned vectored wait wand weak0 weak1 while wire wor xnor xor
  • 11.  List of Keywords Value Set  Verilog supports four values and eight strengths to model the functionality of real hardware. The four value levels are: Value Level Condition in Hardware Circuits 0 Logic zero, false condition 1 Logic one, true condition x Unknown logic value z High impedance, floating state  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 following strength levels Strength Level Type Degree supply Driving strongest strong Driving pull Driving large Storage www.iiu.edu.pk Sunday, May 17, 2015 Data Types in Verilog (1) 11
  • 12. Strength Level Type Degree weak Driving medium Storage small Storage highz High Impedance weakest  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.  For Example; 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. www.iiu.edu.pk Sunday, May 17, 2015 Data Types in Verilog (2) 12
  • 13.  Wires or Nets : represents a physical wire in a circuit and is used to connect gates or modules. A wire does not store its value but must be driven by a continuous assignment statement or by connecting it to the output of a gate or module.  Nets get the output value of their drivers. If a net has no driver, it gets the value z. wire a; // Declare net a for the above circuit wire b,c; // Declare two wires b,c for the above circuit wire d = 1'b0; // Net d is fixed to logic value 0 at declaration.  Other specific types of wires include:  wand ( output of a wand is logical AND of all the drivers connected to it.)  wor (output of wor is logical OR of all the drivers connected to it.)  tri (to join output of multiple tri state buffers) wire a,b; wand d; assign d = a; assign d = b; // d is logical and of a and b www.iiu.edu.pk Sunday, May 17, 2015 Data Types in Verilog (3) 13
  • 14.  Registers: A reg is a Verilog variable type and does not necessarily imply a physical register. In multi-bit registers, data is stored as unsigned numbers and no sign extension is done for what the user might have thought were two’s complement numbers.  Unlike a net, a register does not need a driver. Values of registers can be changed anytime in a simulation by assigning a new value to the register.  The default value for a reg data type is x. reg reset; // declare a variable reset that can hold its value initial // this construct will be discussed later begin reset = 1'b1; // initialize reset to 1 to reset the digital circuit. #100 reset = 1'b0; // after 100 time units reset is deasserted. end  Registers can also be declared as signed variables. Such registers can be used for signed arithmetic for example. reg signed [63:0] m; // 64 bit signed value integer i; // 32 bit signed value . www.iiu.edu.pk Sunday, May 17, 2015 Data Types in Verilog (4) 14
  • 15.  Vectors: Nets or reg data types can be declared as vectors (multiple bit widths). If bit width is not specified, the default is scalar (1-bit). wire a; // scalar net variable, default reg [7:0] PortA; // 8-bit Program Counter Register reg [31:0] ACC, AR , IR; // 3 registers reg clock; // scalar register, default reg [0:40] abs_addr; // Vector register, absolute address 41 bits wide  Vectors can be declared at [high# : low#] or [low# : high#], but the left number in the squared brackets is always the most significant bit of the vector. In the example shown above, bit 0 is the most significant bit of vector virtual_addr.  Vector Part Select: it possible to address bits or parts of vectors. initial begin PortA[7] =1'b1; // bit # 7 of vector AR[2:0]=3'b1zx; // Three least significant bits of Address Register, // using AR[0:2] is illegal. the significant bit should // always be on the left of a range specification abs_addr[0:1] =2'b11; end // Two most significant bits of vector virtual_addr www.iiu.edu.pk Sunday, May 17, 2015 Data Types in Verilog (5) 15
  • 16.  Variable Vector Part Select Another ability provided in Verilog HDl is to have variable part selects of a vector. This allows part selects to be put in for loops to select various parts of the vector. There are two special part-select operators: [<starting_bit>+:width] - part-select increments from starting bit [<starting_bit>-:width] - part-select decrements from starting bit The starting bit of the part select can be varied, but the width has to be constant. reg [255:0] data1; // Little endian notation reg [0:255] data2; // Big endian notation reg [7:0] byte, j; // Using a variable part select, one can choose parts initial begin byte = data1[31-:8]; // starting bit = 31, width =8 => data[31:24] byte = data1[24+:8]; // starting bit = 24, width =8 => data[31:24] byte = data2[31-:8]; // starting bit = 31, width =8 => data[24:31] byte = data2[24+:8]; end// starting bit = 24, width =8 => data[24:31] // The starting bit can also be a variable. The width has to be constant. Therefore, // one can use the variable part select in a loop to select all bytes of the vector. www.iiu.edu.pk Sunday, May 17, 2015 Data Types in Verilog (6) 16
  • 17. for (j=0; j<=31; j=j+1) byte = data1[(j*8)+:8]; // Sequence is [7:0], [15:8]... [255:248] // Can initialize a part of the vector data1[(byteNum*8)+:8] = 8'b0; // If byteNum = 1, clear 8 bits [15:8]  Integer , Real, and Time Register Data Types integer, real, and time register data types are supported in Verilog.  Integer: An integer is a general purpose register data type used for manipulating quantities. Integers are declared by the keyword integer. Although it is possible to use reg as a general-purpose variable, it is more convenient to declare an integer variable for purposes such as counting. The default width for an integer is the host-machine word size, which is implementation-specific but is at least 32 bits. Registers declared as data type reg store values as unsigned quantities, whereas integers store values as signed quantities. integer counter; // general purpose variable used as a counter. initial counter = -1; // A negative one is stored in the counter www.iiu.edu.pk Sunday, May 17, 2015 Data Types in Verilog (7) 17
  • 18.  Real: Real number constants and real register data types are declared with the keyword real. They can be specified in decimal notation (e.g., 3.14) or in scientific notation (e.g., 3e6, which is 3 x 106 ). Real numbers cannot have a range declaration, and their default value is 0. When a real value is assigned to an integer, the real number is rounded off to the nearest integer. real delta; // Define a real variable called delta initial begin delta = 4e10; // delta is assigned in scientific notation delta = 2.13; // delta is assigned a value 2.13 end integer i; // Define an integer i initial i = delta; // i gets the value 2 (rounded value of 2.13) www.iiu.edu.pk Sunday, May 17, 2015 Data Types in Verilog (8) 18
  • 19.  Time: Verilog simulation is done with respect to simulation time. A special time register data type is used in Verilog to store simulation time. A time variable is declared with the keyword time. The width for time register data types is implementation-specific but is at least 64 bits.The system function $time is invoked to get the current simulation time. time save_sim_time; // Define a time variable save_sim_time initial save_sim_time = $time; // Save the current simulation time  Arrays: single and multi dimensional arrays can be made in verilog. Arrays are accessed by <array_name>[<subscript>]. For multi-dimensional arrays, indexes need to be provided for each dimension. integer count[0:7]; // An array of 8 count variables reg bool[31:0]; // Array of 32 one-bit boolean register variables time chk_point[1:100]; // Array of 100 time checkpoint variables reg [4:0] port_id[0:7]; // Array of 8 port_ids; each port_id is 5 bits wide integer matrix[4:0][0:255]; // Two dimensional array of integers www.iiu.edu.pk Sunday, May 17, 2015 Data Types in Verilog (9) 19
  • 20. reg [63:0] array_4d [15:0][7:0][7:0][255:0]; // Four dimensional array wire [7:0] w_array2 [5:0]; // Declare an array of 8 bit vector wire wire w_array1[7:0][5:0]; // Declare an array of single bit wires It is important not to confuse arrays with net or register vectors. A vector is a single element that is n-bits wide. On the other hand, arrays are multiple elements that are 1-bit or n-bits wide. count[5] = 0; // Reset 5th element of array of count variables chk_point[100] = 0; // Reset 100th time check point value port_id[3] = 0; // Reset 3rd element (a 5-bit value) of port_id array. matrix[1][0] = 33559; // Set value of element indexed by [1][0] to 33559 array_4d[0][0][0][0][15:0] = 0; // Clear bits 15:0 of the register // accessed by indices [0][0][0][0] port_id = 0; // Illegal syntax - Attempt to www.iiu.edu.pk Sunday, May 17, 2015 Data Types in Verilog (10) 20
  • 21. write the entire array matrix [1] = 0; // Illegal syntax - Attempt to write [1][0]..[1] [255]  Memories: In digital simulation, one often needs to model register files, RAMs, and ROMs. Memories are modeled in Verilog simply as a one-dimensional array of registers. Each element of the array is known as an element or word and is addressed by a single array index. Each word can be one or more bits. It is important to differentiate between n 1-bit registers and one n-bit register. reg mem1bit[0:1023]; // Memory mem1bit with 1K 1-bit words reg [7:0] membyte[0:1023]; // Memory membyte with 1K 8-bit words(bytes) membyte[511] // Fetches 1 byte word whose address is 511 reg [7:0] RAM1 [15:0]; // 16 Bytes RAM reg [15:0] RAM2[2047:0]; // 2K Words RAM www.iiu.edu.pk Sunday, May 17, 2015 Data Types in Verilog (11) 21
  翻译: