EE2026 - L3 - Verilog Intro
EE2026 - L3 - Verilog Intro
Digital Fundamentals
Introduction to Verilog
Massimo Alioto
Dept of Electrical and Computer Engineering
Email: [email protected]
1
Outline
• Introduction: Hardware Description
Languages
• Introduction to Verilog
– modules, inputs, outputs
– operators
– definition of Boolean expressions
2
Hardware Description Languages
• HDL = software programming language to model
the intended operation of a piece of hardware
• HDL vs programming languages
HDLs Programming languages
• concurrent execution • sequential execution
• account for timing • no timing information
• designed for HW modeling • permit HW modeling
• designed for HW synthesis • can be potentially used to
synthesize HW (difficult)
Behavioral
clock
register
combinational
description RTL description
expressions
directives (area,
time, resources)
Fitting
IOE IOE IOE IOE IOE IOE IOE IOE IOE IOE I/O Element
(IOE)
IOE
Row
IOE
IOE
Local
programming simulation
Interconnect
EAB
Logic Element
(LE)
IOE IOE
Row
IOE IOE
Logic Array
EAB
Logic Array
Block (LAB)
Embedded
IOE IOE IOE IOE IOE IOE IOE IOE IOE IOE Array Block
(EAB)
2K Bits RAM
4
Verilog
module pound_one;
reg [7:0] a,a$b,b,c; // register declarations
reg clk;
initial
begin
clk=0; // initialize the clock
c = 1;
forever #25 clk = !clk;
end
/* This section of code implements
a pipeline */
always @ (posedge clk)
begin
a = b;
b = c;
end
endmodule
7
Identifiers in Verilog
9
Data Types
• physical connections between devices
Nets • wire and tri (identical, typically: distinguish tristate nodes)
• no memory: continuously assigned (driven) by an assignment
wire a,b; // scalar wires
wire [7:0] in_bus; // multi-bit wire (bus)
Parameters
• constants
parameter [2:0] a = 1; // 3-bit (little endian, [0:2] ok – big endian)
parameter width = 8; // default width for parameterizable design
10
Numbers
• Constant numbers are integer or real constants .
• Integers may be sized or unsized
– Syntax: <size>'<base><value> where:
• <size> is the number of bits
• <base is b or B (binary), o or O (octal), d or D (decimal), h or
H (hex)
• <value> is 0-9 a-f A-F x X z Z ? _
• Examples: 2'b01, 6'o243, 78, 4'ha
11
Examples
12
Operators
• Verilog operators (in increasing order of precedence)
– ?: (conditional – cond_expr ? true_expr : false_expr)
– || (logical or – used when checking conditions)
– && (logical and – used when checking conditions)
– | (bitwise or)
– ~| (bitwise nor)
– ^ (bitwise xor)
– ^~ (or ~^) (bitwise xnor, equivalence) if bitwise operands have different bit width,
– & (bitwise and) the shorter one is zero-extended in MSBs
– ~& (bitwise nand)
– == (logical) != (logical) === (case – including x and z) !== (case – including x and
z)
– < (lower than)
– <= (lower than or equal to)
– > (greater than)
– >= (greater than or equal to)
– << (shift left)
– >> (shift right)
– + (addition), - (subtraction), * (multiply), / (divide), % (modulus)
13
Code Structure: Modules
Module
Covers different
levels of
Ports abstraction
interfaces behavioral vs structural
description
15
Module Port Declaration
16
Port Connection Rules
inputs need to be specified continuously
• Inputs (otherwise, value would be unclear)
– internally, must be of net data type
– externally, may be connected to reg or net data type