Verilog Operators: Contents of The Lecture
Verilog Operators: Contents of The Lecture
Lecture 15
Verilog Operators
Contents of the lecture
GMR Institute of Technology
Verilog Operators
(1) Bitwise operators
(2) Logical Operators
(3) Reduction Operators
(4) Arithmetic Operator
(5) Relational Operator
(6) Equality Operator
(7) Shift Operator
(8) Concatenate Operator
(9) Conditional Operator
(10) Replication Operator
Bitwise Operator
31
Bitwise Operator
Let A[2:0], B[2:0] and C[2:0] are three-bit vectors and f and w are two scalars
produces the result C(2) = A(2)’, C(1) = A(1)’, and C(0) = A(0)’
32
Bitwise Operator
produces the result C(2) = A(2).B(2), C(1) = A(1).B(1), and C(0) = A(0).B(0)
GMR Institute of Technology
The statement C= A | B;
produces the result C(2) = A(2)|B(2), C(1) = A(1)|B(1), and C(0) = A(0)|B(0)
33
Bitwise Operator
The statement C= A ^ B;
produces the result C(2) = A(2)^B(2), C(1) = A(1)^B(1), and C(0) = A(0)^B(0)
GMR Institute of Technology
The statement C= A ~^ B;
produces the result C(2) = A(2)~^B(2), C(1) = A(1)~^B(1), and C(0) = A(0)~^B(0)
34
GMR Institute of Technology
Bitwise Operator
35
System Design using Verilog
Lecture 16
Verilog Operators (Continue) ………
Contents of the lecture
GMR Institute of Technology
Verilog Operators
(1) Bitwise operators
(2) Logical Operators
(3) Reduction Operators
(4) Arithmetic Operator
(5) Relational Operator
(6) Equality Operator
(7) Shift Operator
(8) Concatenate Operator
(9) Conditional Operator
(10) Replication Operator
Logical Operators
Logical ! NOT 1
&& AND 2
|| OR 2
37
Logical Operators
Let A[2:0], B[2:0] and C[2:0] are three-bit vectors and f and w are two scalars
(a) The ! operator has the same effect on a scalar operand as the ∼ operator.
For Example
f = !w will produce f=w’
f=∼w will produce f=w’
For Example
The statement f=!A;
produces the result f = [A(2)+A(1)+A(0)]’
38
Logical Operators
39
Reduction Operators
40
Reduction Operators
(i) The & operator implement ‘AND’ operation on all bits of single vector operand
and produce single bit result
(ii) The ~& operator implement ‘NAND’ operation on all bits of single vector
operand and produce single bit result
41
Reduction Operators
(iii) The | operator implement ‘OR’ operation on all bits of single vector operand
and produce single bit result
(iv) The ~| operator implement ‘NOR’ operation on all bits of single vector
operand and produce single bit result
42
Reduction Operators
(v) The ^ operator implement ‘XOR’ operation on all bits of single vector operand
and produce single bit result
(vi) The ~^ operator implement ‘XNOR’ operation on all bits of single vector
operand and produce single bit result
The statement f= ~^ A;
produces the result f = [A(2) xor A(1) xor A(0)]’
43
System Design using Verilog
Lecture 17
Verilog Operators (Continue) ………
Contents of the lecture
GMR Institute of Technology
Verilog Operators
(1) Bitwise operators
(2) Logical Operators
(3) Reduction Operators
(4) Arithmetic Operator
(5) Relational Operator
(6) Equality Operator
(7) Shift Operator
(8) Concatenate Operator
(9) Conditional Operator
(10) Replication Operator
(4) Arithmetic Operators: They perform standard arithmetic operations.
Arithmetic + Addition 2
− Subtraction 2
− 2’s complement 1
∗ Multiplication 2
/ Division 2
45
Example of “+” operator
module adder(a,b,c);
input [2:0]a;
input [2:0]b;
GMR Institute of Technology
output [2:0]c;
assign c=a + b;
endmodule
46
(5) Relational Operators: They perform standard relation operations.
The relational operators are typically used as conditions in if-else and for
statements.
47
(6) Equality Operators
!= Logical Inequality 2
48
(7) Shift Operators
Number of
Operator type Operator symbols Operation performed operands
GMR Institute of Technology
Example1
B=A<<1;
results in B[2] = A[1], B[1] = A[0] and B[0] = 0
Example2
B=A>>1;
results in B[2] = 0, B[1] = A[2] and B[0] = A[1]
49
Shift Operators
B=A>>1;
GMR Institute of Technology
B=A<<1;
results in B[2] = A[1], B[1] = A[0] and B[0] = 0
50
System Design using Verilog
Lecture 18
Verilog Operators (Continue) ………
Contents of the lecture
GMR Institute of Technology
Verilog Operators
(1) Bitwise operators
(2) Logical Operators
(3) Reduction Operators
(4) Arithmetic Operator
(5) Relational Operator
(6) Equality Operator
(7) Shift Operator
(8) Concatenate Operator
(9) Conditional Operator
(10) Replication Operator
(8) Concatenate Operator: This operator concatenates two or more vectors
to create a larger vector
Number of
GMR Institute of Technology
52
Concatenate Operator
Example1
Let A and B are two 3 bit vectors and D is a 6 bit vector
Then D= {A,B}
GMR Institute of Technology
Example2
E = {3’b111, A, 2’b00};
Number of
Operator type Operator symbols Operation performed operands
GMR Institute of Technology
Conditional ?: Concatenation 3
Syntax
54
Conditional Operator
syntax
conditional_expression ? true_expression : false_expression
GMR Institute of Technology
Example-1
A= (B<C)?(D+5): (D+2);
55
Example: A 2-to-1 multiplexer specified using the conditional operator.
GMR Institute of Technology
output f;
assign f = s ? w1 : w0;
endmodule
56
(10) Replication Operator: This operator allows repetitive concatenation of the
same vector, which is replicated the number of times indicated in the replication
constant.
Number of
GMR Institute of Technology
57
Replication Operator
Example-1
{3{A}}
GMR Institute of Technology
results {A, A, A}
Example-2
{4{2’b10}}
Example-3
{2{A}, 3{B}}
Results to {A, A, B, B, B} 58