internship_basics of verilog_new1.pptx
internship_basics of verilog_new1.pptx
Presented By
Anjaly Joseph T
(JRF)
What is Verilog?
● Verilog is a hardware description language.
● Developed in 1984.
● Verilog is used not only for design, but also for simulation and testing
● Concurrency is the core feature of Verilog, enabling parallel execution that software languages like C or
Python cannot natively achieve
Valid Module Name Rules
• Must begin with a letter (A–Z or a–z)
• Should not be a Verilog reserved keyword (like module, input, always, etc.)
counter_4bit)
• Verilog modules use ports to communicate with the outside world —
Values Definitions
x Unknown value
7
Numbers
● Binary : b or B
● Octal : o or O
● Decimal : d or D
● Hexadecimal : h or H
● Syntax : <size>’<base><number>.
● Example : 4’b0001, 4’d12
Data Types in Verilog
A storage format having a specific range or type is called data type. They can
be divided into two groups.
1. Nets
2. Registers / Variables
Common Net Types
● Example : reg y;
Vectors
● In Verilog, you can instantiate inbuilt (primitive) logic gates directly without needing to define them
yourself.
● These gates are part of Verilog’s built-in library of gate-level primitives and are commonly used for
structural modeling
● Available Gate primitives are
1. and
2. or
3. not
4. nand
5. nor
6. xor
7. xnor
8. buf
Verilog Operators
1. Arithmetic Operators
2. Logical Operators
3. Equality Operators
4. Relational Operators
5. Bitwise Operators
6. Conditional Operators
7. Shift Operators
8. Reduction Operators
9. Concatenation Operators
10. Replication Operators
Arithmetic Operators
Operators Number of operands Description
+ 2 addition
- 2 subtraction
* 2 multiplication
/ 2 division
assign sum = a + b;
endmodule
Logical Operators
• Operates on entire value
• Result is 1 bit value
• Commonly used in if , case, always etc
! 1 Logical negation
|| 2 Logical or
Eg:-
| 2 Bitwise or
~ 1 Bitwise not
^ 2 Bitwise xor
^~ or ~^ 2 Bitwise xnor
== 2 Equality
!= 2 Inequality
● The equality and inequality operator compares two operands bit by bit and
results to 1 or 0 if true or false respectively. They will return value as ‘x’ if either
operand has x or z bits.
Relational Operators
Operators Number of operands Description
?: 3 conditional
Syntax:
assign equal=(a==b)?1’b1:1’b0;
assign less_than =(a<b)?1’b1:1’b0;
assign greater_than =(a>b)?1’b1:1’b0;
endmodule
Shift Operators
Operators Number of operands Description
● Logical shift operators shift a vector to left or right by a specified number of bits and fill vacant bit positions
with zeros.
● Arithmetic shift operators shift a vector to right by a specified number of bits and fill vacant bit positions
with sign bit if an expression is signed, otherwise with zeros.
Example
module shift_4bit ( data_in = 4'b1010; // Decimal 10
input [3:0] data_in,
output [3:0] lshift,
output [3:0] rshift,
Operation Result Comment
output [3:0] arith_lshift,
output [3:0] arith_rshift data_in << 1 0100 (4) Left shift by 1 bit
); data_in >> 1 0101 (5) Right shift by 1 bit
data_in <<< 1 0100 (4) Same as <<
assign lshift = data_in << 1; Same as >> if
assign rshift = data_in >> 1; data_in >>> 1 0101 (5)
unsigned
assign arith_lshift = data_in <<< 1;
assign arith_rshift = data_in >>> 1;
endmodule
Reduction Operators
Operators Number of operands Description
| 1 Reduction or
^ 1 Reduction xor
~| 1 Reduction nor
~^ or ^~ 1 Reduction xnor
● The reduction operators give 1-bit output by performing the bitwise operation over
a single vector operand.
● Reduction operators work bit by bit from right to left.
Example
module reduction_example(
Input [3:0]a,
Output and_reduction, or_reduction, xor_reduction, nand_reduction, nor_reduction, xnor_reduction);
assign and_reduction = &a; // AND of all bits
assign or_reduction = |a; // OR of all bits
assign xor_reduction = ^a; // XOR of all bits
assign nand_reduction= ~&a; // NAND of all bits
Output
assign nor_reduction = ~|a; // NOR of all bits
and_reduction = 0
assign xnor_reduction= ~^a; // XNOR of all bits or_reduction = 1
endmodule xor_reduction = 1
nand_reduction = 1
nor_reduction = 0
xnor_reduction = 0
Concatenation Operator
module example(
input [3:0] a,b, Output
output [7:0] concat_result ); a= 4'b1010;
b = 4'b0101
concat_result =
assign concat_result = {a, b}; 8'b10100101 (decimal
endmodule 165)
Replication Operator
module example
( Output
Input reg [1:0]
result = 6'b101010
output [5:0] result); (decimal 42)
assign result = {3{a}};
endmodule
Comments
● There are two ways of writing comments in verilog.
and structure.
● Verilog supports multiple modeling styles, allowing you to describe a circuit in different ways
2. Dataflow Modeling
3. Behavioral Modeling
Structural Modeling (Gate-level)
• Describes the circuit using gate-level components.
• Example:
and a1 (out1, in1, in2);
or o1 (out2, in1, in2);
module and_gate
(
input A, input B,
output Y,
);
endmodule
Dataflow Modeling
• Focuses on how data flows through the system.
• Example:
and_gate uut (
.a(a),
.b(b),
.y(y)
);
endmodule
and_gate uut (
.a(a),
.b(b),
.y(y)
);
endmodule