SlideShare uma empresa Scribd logo
1 de 21
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

Mais conteúdo relacionado

Mais procurados

Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)Alok Singh
 
Verilog Tasks & Functions
Verilog Tasks & FunctionsVerilog Tasks & Functions
Verilog Tasks & Functionsanand hd
 
Verilog 語法教學
Verilog 語法教學 Verilog 語法教學
Verilog 語法教學 艾鍗科技
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorialraju reddy
 
Session 8 assertion_based_verification_and_interfaces
Session 8 assertion_based_verification_and_interfacesSession 8 assertion_based_verification_and_interfaces
Session 8 assertion_based_verification_and_interfacesNirav Desai
 
UVM Methodology Tutorial
UVM Methodology TutorialUVM Methodology Tutorial
UVM Methodology TutorialArrow Devices
 
Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...
Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...
Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...Sameh El-Ashry
 
Session 9 advance_verification_features
Session 9 advance_verification_featuresSession 9 advance_verification_features
Session 9 advance_verification_featuresNirav Desai
 

Mais procurados (20)

Arbiters
ArbitersArbiters
Arbiters
 
Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)
 
Verilog Tasks and functions
Verilog Tasks and functionsVerilog Tasks and functions
Verilog Tasks and functions
 
VHDL CODES
VHDL CODES VHDL CODES
VHDL CODES
 
Data types in verilog
Data types in verilogData types in verilog
Data types in verilog
 
VHDL
VHDLVHDL
VHDL
 
system verilog
system verilogsystem verilog
system verilog
 
Fpga
FpgaFpga
Fpga
 
Verilog Tasks & Functions
Verilog Tasks & FunctionsVerilog Tasks & Functions
Verilog Tasks & Functions
 
Verilog 語法教學
Verilog 語法教學 Verilog 語法教學
Verilog 語法教學
 
Verilog
VerilogVerilog
Verilog
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
Session 8 assertion_based_verification_and_interfaces
Session 8 assertion_based_verification_and_interfacesSession 8 assertion_based_verification_and_interfaces
Session 8 assertion_based_verification_and_interfaces
 
UVM Methodology Tutorial
UVM Methodology TutorialUVM Methodology Tutorial
UVM Methodology Tutorial
 
verilog
verilogverilog
verilog
 
Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...
Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...
Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...
 
verilog code
verilog codeverilog code
verilog code
 
Fpga & VHDL
Fpga & VHDLFpga & VHDL
Fpga & VHDL
 
axi protocol
axi protocolaxi protocol
axi protocol
 
Session 9 advance_verification_features
Session 9 advance_verification_featuresSession 9 advance_verification_features
Session 9 advance_verification_features
 

Semelhante a Fpga 05-verilog-programming

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-adderMalik Tauqir Hasan
 
Verilog Final Probe'22.pptx
Verilog Final Probe'22.pptxVerilog Final Probe'22.pptx
Verilog Final Probe'22.pptxSyedAzim6
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhtsBéo Tú
 
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 firstcprogramprincepavan
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogramprincepavan
 
System Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLSystem Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLE2MATRIX
 
VIT_Workshop.ppt
VIT_Workshop.pptVIT_Workshop.ppt
VIT_Workshop.pptVINOTHRAJR1
 
vlsi design using verilog presentaion 1
vlsi design using verilog   presentaion 1vlsi design using verilog   presentaion 1
vlsi design using verilog presentaion 1MANDHASAIGOUD1
 
SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2alhadi81
 
Verilog_Overview.pdf
Verilog_Overview.pdfVerilog_Overview.pdf
Verilog_Overview.pdfQuangHuyDo3
 
System design using HDL - Module 1
System design using HDL - Module 1System design using HDL - Module 1
System design using HDL - Module 1Aravinda Koithyar
 

Semelhante a 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
 
Verilogspk1
Verilogspk1Verilogspk1
Verilogspk1
 
Verilog Final Probe'22.pptx
Verilog Final Probe'22.pptxVerilog Final Probe'22.pptx
Verilog Final Probe'22.pptx
 
Verilog HDL
Verilog HDL Verilog HDL
Verilog HDL
 
VHDL- data types
VHDL- data typesVHDL- data types
VHDL- data types
 
DDUV.pdf
DDUV.pdfDDUV.pdf
DDUV.pdf
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhts
 
Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
 
C Programming
C ProgrammingC Programming
C Programming
 
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)
 
Fpga 04-verilog-programming
Fpga 04-verilog-programmingFpga 04-verilog-programming
Fpga 04-verilog-programming
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
 
System Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLSystem Verilog Tutorial - VHDL
System Verilog Tutorial - VHDL
 
VIT_Workshop.ppt
VIT_Workshop.pptVIT_Workshop.ppt
VIT_Workshop.ppt
 
vlsi design using verilog presentaion 1
vlsi design using verilog   presentaion 1vlsi design using verilog   presentaion 1
vlsi design using verilog presentaion 1
 
Spdas2 vlsibput
Spdas2 vlsibputSpdas2 vlsibput
Spdas2 vlsibput
 
SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2
 
Verilog_Overview.pdf
Verilog_Overview.pdfVerilog_Overview.pdf
Verilog_Overview.pdf
 
System design using HDL - Module 1
System design using HDL - Module 1System design using HDL - Module 1
System design using HDL - Module 1
 

Mais de 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-filterMalik 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-encodingMalik Tauqir Hasan
 
Fpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machineFpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machineMalik Tauqir Hasan
 
Fpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineFpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineMalik 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-directivesMalik Tauqir Hasan
 

Mais de Malik Tauqir Hasan (10)

Fpga 13-task-and-functions
Fpga 13-task-and-functionsFpga 13-task-and-functions
Fpga 13-task-and-functions
 
Fpga 12-event-control
Fpga 12-event-controlFpga 12-event-control
Fpga 12-event-control
 
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
 
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
 
Fpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machineFpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machine
 
Fpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineFpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machine
 
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
 
Fpga 03-cpld-and-fpga
Fpga 03-cpld-and-fpgaFpga 03-cpld-and-fpga
Fpga 03-cpld-and-fpga
 
Fpga 02-memory-and-pl ds
Fpga 02-memory-and-pl dsFpga 02-memory-and-pl ds
Fpga 02-memory-and-pl ds
 
Fpga 01-digital-logic-design
Fpga 01-digital-logic-designFpga 01-digital-logic-design
Fpga 01-digital-logic-design
 

Último

Dubai Call Girls O525547819 Spring Break Fast Call Girls Dubai
Dubai Call Girls O525547819 Spring Break Fast Call Girls DubaiDubai Call Girls O525547819 Spring Break Fast Call Girls Dubai
Dubai Call Girls O525547819 Spring Break Fast Call Girls Dubaikojalkojal131
 
NO1 Certified Vashikaran Specialist in Uk Black Magic Specialist in Uk Black ...
NO1 Certified Vashikaran Specialist in Uk Black Magic Specialist in Uk Black ...NO1 Certified Vashikaran Specialist in Uk Black Magic Specialist in Uk Black ...
NO1 Certified Vashikaran Specialist in Uk Black Magic Specialist in Uk Black ...Amil baba
 
RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作f3774p8b
 
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degreeyuu sss
 
Vip Udupi Call Girls 7001305949 WhatsApp Number 24x7 Best Services
Vip Udupi Call Girls 7001305949 WhatsApp Number 24x7 Best ServicesVip Udupi Call Girls 7001305949 WhatsApp Number 24x7 Best Services
Vip Udupi Call Girls 7001305949 WhatsApp Number 24x7 Best Servicesnajka9823
 
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作ss846v0c
 
existing product research b2 Sunderland Culture
existing product research b2 Sunderland Cultureexisting product research b2 Sunderland Culture
existing product research b2 Sunderland CultureChloeMeadows1
 
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作f3774p8b
 
澳洲Deakin学位证,迪肯大学毕业证书1:1制作
澳洲Deakin学位证,迪肯大学毕业证书1:1制作澳洲Deakin学位证,迪肯大学毕业证书1:1制作
澳洲Deakin学位证,迪肯大学毕业证书1:1制作rpb5qxou
 
NO1 Certified Black Magic Specialist Expert In Bahawalpur, Sargodha, Sialkot,...
NO1 Certified Black Magic Specialist Expert In Bahawalpur, Sargodha, Sialkot,...NO1 Certified Black Magic Specialist Expert In Bahawalpur, Sargodha, Sialkot,...
NO1 Certified Black Magic Specialist Expert In Bahawalpur, Sargodha, Sialkot,...Amil Baba Dawood bangali
 
毕业文凭制作#回国入职#diploma#degree美国威斯康星大学麦迪逊分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#d...
毕业文凭制作#回国入职#diploma#degree美国威斯康星大学麦迪逊分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#d...毕业文凭制作#回国入职#diploma#degree美国威斯康星大学麦迪逊分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#d...
毕业文凭制作#回国入职#diploma#degree美国威斯康星大学麦迪逊分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#d...ttt fff
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...Amil Baba Dawood bangali
 
Computer Organization and Architecture 10th - William Stallings, Ch01.pdf
Computer Organization and Architecture 10th - William Stallings, Ch01.pdfComputer Organization and Architecture 10th - William Stallings, Ch01.pdf
Computer Organization and Architecture 10th - William Stallings, Ch01.pdfShahdAbdElsamea2
 
办理(CSU毕业证书)澳洲查理斯特大学毕业证成绩单原版一比一
办理(CSU毕业证书)澳洲查理斯特大学毕业证成绩单原版一比一办理(CSU毕业证书)澳洲查理斯特大学毕业证成绩单原版一比一
办理(CSU毕业证书)澳洲查理斯特大学毕业证成绩单原版一比一diploma 1
 
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...Amil baba
 
Call Girls In Munirka>༒9599632723 Incall_OutCall Available
Call Girls In Munirka>༒9599632723 Incall_OutCall AvailableCall Girls In Munirka>༒9599632723 Incall_OutCall Available
Call Girls In Munirka>༒9599632723 Incall_OutCall AvailableCall Girls in Delhi
 
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degreeyuu sss
 
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)861c7ca49a02
 
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degreeyuu sss
 

Último (20)

Dubai Call Girls O525547819 Spring Break Fast Call Girls Dubai
Dubai Call Girls O525547819 Spring Break Fast Call Girls DubaiDubai Call Girls O525547819 Spring Break Fast Call Girls Dubai
Dubai Call Girls O525547819 Spring Break Fast Call Girls Dubai
 
NO1 Certified Vashikaran Specialist in Uk Black Magic Specialist in Uk Black ...
NO1 Certified Vashikaran Specialist in Uk Black Magic Specialist in Uk Black ...NO1 Certified Vashikaran Specialist in Uk Black Magic Specialist in Uk Black ...
NO1 Certified Vashikaran Specialist in Uk Black Magic Specialist in Uk Black ...
 
RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作
 
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
 
Vip Udupi Call Girls 7001305949 WhatsApp Number 24x7 Best Services
Vip Udupi Call Girls 7001305949 WhatsApp Number 24x7 Best ServicesVip Udupi Call Girls 7001305949 WhatsApp Number 24x7 Best Services
Vip Udupi Call Girls 7001305949 WhatsApp Number 24x7 Best Services
 
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作
 
existing product research b2 Sunderland Culture
existing product research b2 Sunderland Cultureexisting product research b2 Sunderland Culture
existing product research b2 Sunderland Culture
 
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作
 
young call girls in Gtb Nagar,🔝 9953056974 🔝 escort Service
young call girls in Gtb Nagar,🔝 9953056974 🔝 escort Serviceyoung call girls in Gtb Nagar,🔝 9953056974 🔝 escort Service
young call girls in Gtb Nagar,🔝 9953056974 🔝 escort Service
 
澳洲Deakin学位证,迪肯大学毕业证书1:1制作
澳洲Deakin学位证,迪肯大学毕业证书1:1制作澳洲Deakin学位证,迪肯大学毕业证书1:1制作
澳洲Deakin学位证,迪肯大学毕业证书1:1制作
 
NO1 Certified Black Magic Specialist Expert In Bahawalpur, Sargodha, Sialkot,...
NO1 Certified Black Magic Specialist Expert In Bahawalpur, Sargodha, Sialkot,...NO1 Certified Black Magic Specialist Expert In Bahawalpur, Sargodha, Sialkot,...
NO1 Certified Black Magic Specialist Expert In Bahawalpur, Sargodha, Sialkot,...
 
毕业文凭制作#回国入职#diploma#degree美国威斯康星大学麦迪逊分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#d...
毕业文凭制作#回国入职#diploma#degree美国威斯康星大学麦迪逊分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#d...毕业文凭制作#回国入职#diploma#degree美国威斯康星大学麦迪逊分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#d...
毕业文凭制作#回国入职#diploma#degree美国威斯康星大学麦迪逊分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#d...
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...
 
Computer Organization and Architecture 10th - William Stallings, Ch01.pdf
Computer Organization and Architecture 10th - William Stallings, Ch01.pdfComputer Organization and Architecture 10th - William Stallings, Ch01.pdf
Computer Organization and Architecture 10th - William Stallings, Ch01.pdf
 
办理(CSU毕业证书)澳洲查理斯特大学毕业证成绩单原版一比一
办理(CSU毕业证书)澳洲查理斯特大学毕业证成绩单原版一比一办理(CSU毕业证书)澳洲查理斯特大学毕业证成绩单原版一比一
办理(CSU毕业证书)澳洲查理斯特大学毕业证成绩单原版一比一
 
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...
 
Call Girls In Munirka>༒9599632723 Incall_OutCall Available
Call Girls In Munirka>༒9599632723 Incall_OutCall AvailableCall Girls In Munirka>༒9599632723 Incall_OutCall Available
Call Girls In Munirka>༒9599632723 Incall_OutCall Available
 
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
 
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
 
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
 

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