SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Session 7 code_functional_coverage
Session 7 code_functional_coverageSession 7 code_functional_coverage
Session 7 code_functional_coverageNirav Desai
 
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 ExamplesE2MATRIX
 
Basic concepts in Verilog HDL
Basic concepts in Verilog HDLBasic concepts in Verilog HDL
Basic concepts in Verilog HDLanand hd
 
Binary multipliers
Binary multipliersBinary multipliers
Binary multipliersSyed Saeed
 
System verilog coverage
System verilog coverageSystem verilog coverage
System verilog coveragePushpa Yakkala
 
Day2 Verilog HDL Basic
Day2 Verilog HDL BasicDay2 Verilog HDL Basic
Day2 Verilog HDL BasicRon Liu
 
System verilog assertions
System verilog assertionsSystem verilog assertions
System verilog assertionsHARINATH REDDY
 
Fpga(field programmable gate array)
Fpga(field programmable gate array) Fpga(field programmable gate array)
Fpga(field programmable gate array) Iffat Anjum
 
Verilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and EncoderVerilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and EncoderBharti Airtel Ltd.
 
Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardJian-Hong Pan
 
Data flow model -Lecture-4
Data flow model -Lecture-4Data flow model -Lecture-4
Data flow model -Lecture-4Dr.YNM
 
Experiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gatesExperiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gatesRicardo Castro
 
Verilog operators.pptx
Verilog  operators.pptxVerilog  operators.pptx
Verilog operators.pptxVandanaPagar1
 
Verilog 語法教學
Verilog 語法教學 Verilog 語法教學
Verilog 語法教學 艾鍗科技
 

Was ist angesagt? (20)

PAL And PLA ROM
PAL And PLA ROMPAL And PLA ROM
PAL And PLA ROM
 
Session 7 code_functional_coverage
Session 7 code_functional_coverageSession 7 code_functional_coverage
Session 7 code_functional_coverage
 
Unit v. HDL Synthesis Process
Unit v. HDL Synthesis ProcessUnit v. HDL Synthesis Process
Unit v. HDL Synthesis Process
 
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
 
Basic concepts in Verilog HDL
Basic concepts in Verilog HDLBasic concepts in Verilog HDL
Basic concepts in Verilog HDL
 
VHDL - Part 2
VHDL - Part 2VHDL - Part 2
VHDL - Part 2
 
Binary multipliers
Binary multipliersBinary multipliers
Binary multipliers
 
System verilog coverage
System verilog coverageSystem verilog coverage
System verilog coverage
 
Day2 Verilog HDL Basic
Day2 Verilog HDL BasicDay2 Verilog HDL Basic
Day2 Verilog HDL Basic
 
System verilog assertions
System verilog assertionsSystem verilog assertions
System verilog assertions
 
Fpga(field programmable gate array)
Fpga(field programmable gate array) Fpga(field programmable gate array)
Fpga(field programmable gate array)
 
Verilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and EncoderVerilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and Encoder
 
virtuoso
virtuosovirtuoso
virtuoso
 
Share the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development Board
 
Data flow model -Lecture-4
Data flow model -Lecture-4Data flow model -Lecture-4
Data flow model -Lecture-4
 
8 bit alu design
8 bit alu design8 bit alu design
8 bit alu design
 
Experiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gatesExperiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gates
 
Report on VLSI
Report on VLSIReport on VLSI
Report on VLSI
 
Verilog operators.pptx
Verilog  operators.pptxVerilog  operators.pptx
Verilog operators.pptx
 
Verilog 語法教學
Verilog 語法教學 Verilog 語法教學
Verilog 語法教學
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Lubrication and it's types and properties of the libricabt
Lubrication and it's types and properties of the libricabtLubrication and it's types and properties of the libricabt
Lubrication and it's types and properties of the libricabtdineshkumar430venkat
 
Develop Keyboard Skill.pptx er power point
Develop Keyboard Skill.pptx er power pointDevelop Keyboard Skill.pptx er power point
Develop Keyboard Skill.pptx er power pointGetawu
 
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...amitlee9823
 
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...amitlee9823
 
9004554577, Get Adorable Call Girls service. Book call girls & escort service...
9004554577, Get Adorable Call Girls service. Book call girls & escort service...9004554577, Get Adorable Call Girls service. Book call girls & escort service...
9004554577, Get Adorable Call Girls service. Book call girls & escort service...Pooja Nehwal
 
VVIP Pune Call Girls Karve Nagar (7001035870) Pune Escorts Nearby with Comple...
VVIP Pune Call Girls Karve Nagar (7001035870) Pune Escorts Nearby with Comple...VVIP Pune Call Girls Karve Nagar (7001035870) Pune Escorts Nearby with Comple...
VVIP Pune Call Girls Karve Nagar (7001035870) Pune Escorts Nearby with Comple...Call Girls in Nagpur High Profile
 
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service Nashik
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service NashikLow Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service Nashik
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...motiram463
 
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...Amil baba
 
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort Girls
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort GirlsDeira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort Girls
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort GirlsEscorts Call Girls
 
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样qaffana
 
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Naicy mandal
 
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Call Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated  Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Top Rated  Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Call Girls in Nagpur High Profile
 
9892124323, Call Girl in Juhu Call Girls Services (Rate ₹8.5K) 24×7 with Hote...
9892124323, Call Girl in Juhu Call Girls Services (Rate ₹8.5K) 24×7 with Hote...9892124323, Call Girl in Juhu Call Girls Services (Rate ₹8.5K) 24×7 with Hote...
9892124323, Call Girl in Juhu Call Girls Services (Rate ₹8.5K) 24×7 with Hote...Pooja Nehwal
 
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...ranjana rawat
 
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...Call Girls in Nagpur High Profile
 

Kürzlich hochgeladen (20)

Lubrication and it's types and properties of the libricabt
Lubrication and it's types and properties of the libricabtLubrication and it's types and properties of the libricabt
Lubrication and it's types and properties of the libricabt
 
CHEAP Call Girls in Mayapuri (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Mayapuri  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Mayapuri  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Mayapuri (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Develop Keyboard Skill.pptx er power point
Develop Keyboard Skill.pptx er power pointDevelop Keyboard Skill.pptx er power point
Develop Keyboard Skill.pptx er power point
 
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
 
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
 
9004554577, Get Adorable Call Girls service. Book call girls & escort service...
9004554577, Get Adorable Call Girls service. Book call girls & escort service...9004554577, Get Adorable Call Girls service. Book call girls & escort service...
9004554577, Get Adorable Call Girls service. Book call girls & escort service...
 
VVIP Pune Call Girls Karve Nagar (7001035870) Pune Escorts Nearby with Comple...
VVIP Pune Call Girls Karve Nagar (7001035870) Pune Escorts Nearby with Comple...VVIP Pune Call Girls Karve Nagar (7001035870) Pune Escorts Nearby with Comple...
VVIP Pune Call Girls Karve Nagar (7001035870) Pune Escorts Nearby with Comple...
 
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service Nashik
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service NashikLow Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service Nashik
Low Rate Call Girls Nashik Vedika 7001305949 Independent Escort Service Nashik
 
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
 
young call girls in Sainik Farm 🔝 9953056974 🔝 Delhi escort Service
young call girls in Sainik Farm 🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Sainik Farm 🔝 9953056974 🔝 Delhi escort Service
young call girls in Sainik Farm 🔝 9953056974 🔝 Delhi escort Service
 
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
NO1 Verified Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi A...
 
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort Girls
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort GirlsDeira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort Girls
Deira Dubai Escorts +0561951007 Escort Service in Dubai by Dubai Escort Girls
 
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
哪里办理美国宾夕法尼亚州立大学毕业证(本硕)psu成绩单原版一模一样
 
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
 
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
Top Rated Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated  Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Top Rated  Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
 
9892124323, Call Girl in Juhu Call Girls Services (Rate ₹8.5K) 24×7 with Hote...
9892124323, Call Girl in Juhu Call Girls Services (Rate ₹8.5K) 24×7 with Hote...9892124323, Call Girl in Juhu Call Girls Services (Rate ₹8.5K) 24×7 with Hote...
9892124323, Call Girl in Juhu Call Girls Services (Rate ₹8.5K) 24×7 with Hote...
 
@Delhi ! CAll GIRLS IN Defence Colony 🦋 9999965857 🤩 Dwarka Call Girls
@Delhi ! CAll GIRLS IN Defence Colony 🦋 9999965857 🤩 Dwarka Call Girls@Delhi ! CAll GIRLS IN Defence Colony 🦋 9999965857 🤩 Dwarka Call Girls
@Delhi ! CAll GIRLS IN Defence Colony 🦋 9999965857 🤩 Dwarka Call Girls
 
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
Book Paid Lohegaon Call Girls Pune 8250192130Low Budget Full Independent High...
 
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...
VVIP Pune Call Girls Warje (7001035870) Pune Escorts Nearby with Complete Sat...
 

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