0% found this document useful (0 votes)
71 views20 pages

12 Verilog Operators 18-01-2023

The document describes different types of operators in hardware description languages: 1) Arithmetic operators perform mathematical operations like multiplication, division, addition, subtraction, and modulus. Logical operators evaluate expressions to true or false. Relational operators compare values. 2) Bitwise operators perform operations on each bit of binary operands. Shift operators shift bits left or right. Reduction operators reduce vectors to a single value. 3) Concatenation operators append operands. Replication operators repeat operands. Conditional operators select between true and false expressions.

Uploaded by

Back up
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views20 pages

12 Verilog Operators 18-01-2023

The document describes different types of operators in hardware description languages: 1) Arithmetic operators perform mathematical operations like multiplication, division, addition, subtraction, and modulus. Logical operators evaluate expressions to true or false. Relational operators compare values. 2) Bitwise operators perform operations on each bit of binary operands. Shift operators shift bits left or right. Reduction operators reduce vectors to a single value. 3) Concatenation operators append operands. Replication operators repeat operands. Conditional operators select between true and false expressions.

Uploaded by

Back up
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Types of Operators

• The operators can be :


arithmetic
logical
relational
equality
bit wise
reduction
shift
concatenation
replication
conditional
Arithmetic operators
• Expressions constitute operators and operands

Operation Symbol Operand

Multiply * binary

Divide / binary

Add + binary

Subtract - binary

Modulus % binary
Arithmetic operator examples
a*b // multiply a and b a=3’b011 b=3’b010 d=4 e=3
a/b // divide a by b c=a * b // c= 3’b110
a+b // add a and b c= a / b // c= 1
c= a+b // c= 3’b101
a-b // subtract b from a c= a-b // c=3’b001
a%b // modulus of a by b c=d/e // c=1

• In arithmetic operations, if any operand bit has a value x, then the result of
the entire expression is x.

• The size of the result is determined by the size of the largest operand.
Logical operators

• Logical operator evaluates always to a one bit value either true(1) or false (0) or
x (unambiguous) . If any operand bit is either x or z it is equivalent to x

Operation Symbol Operand

logical and && binary

logical or || binary

logical not ! binary


Logical operator examples

a1 = 1’b0; // 0 is false;
a=10 b=00
a2 = 1’b1; // 1 is true
a && b // evaluates to 0 ( 1 && 0)
a1 && a2 // is 0 (false)
a=2’b1x b=2’b11
a1 || a2 // is 1 (true)
a || b // is unknown, evaluates to x.
!a2 // is 0 (false)

• For vector operands, a non-zero vector is treated as logical 1.


Relational operators
• Relational operations return logical 0 or 1. If there is any x or z bit in operand
then it will return x.

Operation Symbol Operand


Greater than > Binary
less than < Binary
Greater than or equal to >= Binary

Less than or equal to <= Binary


Relational operator examples

a = 5 b = 6 c = 2’1x

a >b // evaluates to 0

a <= b // evaluates to 1

b >= c // evaluates to x
Equality operators

Operation Symbol Operand

logical equality == binary

logical inequality != binary

case equality === binary

case inequality !== binary


Equality operators
• Equality operator can return 1 or 0.

• Logical equality operator (== !=) will return x if any of the operand
bit has x.

• Case equality operator compares both operand bit by bit including x


and z bit. If it matches then returns 1 or else it returns 0. It doesn’t
return x.
Equality operator Examples

a=3; b=5; c=3’b100; d=3’b101; e=4’b1xxx; f=4’b1xxx; g=3’b1xz

a !=b // evaluates to 1.

e===f // evaluates to 1.

f===g // evaluates to 0.

d == e // evaluates to x
Bitwise operators
Bitwise operations are performed on each bit of the operand

Operation Symbol Operand


Bitwise and & Binary
Bitwise or | Binary
Bitwise negation ~ Unary
Bitwise xor ^ Binary
Bitwise xnor ~^ or ^~ Binary
Bitwise operator Examples
a = 3’b111; b = 3’b101; d = 3’b1x1;

c = ~a; // c = 3’b000

c = a & b; // c = 3’b101

c = a | b; // c = 3’b111

c = a ^ b; // c = 3’b010

c = a | d; // c = 3’b1x1
Reduction operators
• Reduction operators are unary operators
Operation Symbol Operand
reduction and & unary
reduction nand ~& unary
reduction or | unary
reduction nor ~| unary
reduction xor ^ unary
reduction xnor ~^ or ~^ unary
Reduction operator Examples
x = 5’b01100

c = &x // c= 0 & 1 & 1 & 0 & 0 c=0

c = |x // c= 0|1|1|0|0 c=1

c = ^x // c=0^1^1^0^0 c=0
Shift operators
• Shift operator can be shift left or shift right

Operation Symbol Operand


shift right >> unary
shift left << unary

Example:
a = 4’b1011;
y = a >> 2; // y =4’b0010, 0’s filled in MSB
y = a << 2; // y = 4’b1100, 0’s filled in LSB
Concatenation operators
• Concatenation operator is used to append multiple operands.
• The operand must be sized.

Example:
a=3’b101; b=3’b111;

y = {a,b}; // y = 6’b101111
y = {a,b,3’b010}; // y =101111010
Replication operators
Replication operator is used to concatenate same number.

a=3’b101 b =2’b10

y = {2{a}}; // result of y is 6’b101101

y = {2{a},2{b} }; // result of y is 10’b1011011010

y = { 2{a},2’b10}; // result of y is 6’b10110110


Conditional operators
Conditional operator ? :
format:
conditional_expr ? true expr : false expr;
Example:
assign out = control ? I1 : l2;

control out
1 I1
0 I2
Operator precedence

You might also like