Lecture 6
Lecture 6
Lecture 6
Lecture # 6
Introduction to Verilog
Shift Replication
Logical Concatenation
Conditional Equality
Negation Unary Reduction
Relational Bit-wise
3
Shift Operator
module logical_block;
Logical operators (&&,
initial begin
||) produce a scalar
$display (2’b00 && 2’b10); // 0
value (0 1 or X) (0, 1, or $display (2’b01 && 2’b10); // 1
X). $display (2’b00 || 2’b00); // 0
$display (2’b01 || 2’b00); // 1 71
$display (2 b01 || 2 b00); // 1
$display (2’b00 && 2’b1x); // x
$display (2’b1z && 2’b10); // x
end
endmodule
5
Conditional Operator
Negation operator:
(!) logical
(~) bitwise
Reduces an operand to its logical inverse.
9
Other Operators
Relational Operators
Less than (<),
Less than or equal to (<=),
Greater than or equal to (>=),
Greater than (>).
Example: if (A >= 2’b11) then B = 1’b1;
10
Operators: Replication
Replication operator
Replicates an expression a fixed number of times
to form a new vector quantity.
({n{}})
Example
regA = 2’b11;
bus = {4{regA}}; // bus = 11111111
11
Operators: Concatenation
Concatenation operator
Allows you to select bits from different vectors to
join then into a new vector.
{} concatenation
Example
new_vector[8:0] = {regA[4:2],regB[2:1],1’b0,regC[2:0]};
12
Other operators
Example:
16
Unary Reduction Operator
Arithmetic
If any bit is x or z, result is all x’s.
Divide by 0 produces all x’s.
Relational
If any bit is x or z, result is x.
Logical
== and != If any bit is x or z, result is x.
=== and !== All bits including x and z values must match for
equality
19
Expressions with Operands Containing x or z
Bitwise
Defined by tables for 0, 1, x, z operands.
Reduction
Defined by tables as for bitwise operators.
Shifts
z changed to x. Vacated positions zero filled.
20
Expressions with Operands Containing x or z
Conditional
Ifconditional expression is ambiguous (e.g., x
or z), both expressions are evaluated and
bitwise combined as follows: f(1,1) = 1, f(0,0) =
0, otherwise x.
21
Blocking Assignments
Identified by =
Sequence of blocking
assignments executes
sequentially
22
Non-Blocking Assignments
Identified by <=
Sequence of non-blocking
assignments executes
concurrently
/*Calculates b = 2a, c = b + a, d
<= c + a. All values used on RHS
are those at posedge clock. Note
that there are two assignments to
b and c. Only the last one is
effective. */
23
Blocking Assignments – Inter
Assignment Delay
Delays evaluation of
RHS and assignment to
LHS
Delays subsequent
statements
26
Non-Blocking Assignment
Intra-Assignment Delay