Digital Signal Processing Reference
In-Depth Information
Example 2.6
Apply the & reduction operator to a 4-bit number A ¼ 4 0 b1011 :
assign out = &A;
This operation is equivalent to performing a bitwise & operation on all the bits of A :
out = A[0] & A[1] & A[2] & A[3];
2.6.3.8 Bitwise Arithmetic Operators
Bitwise arithmetic operators are also common to software programmers. These operators perform
bitwise operations on all the corresponding bits of the two operands. Table 2.11 gives all the bitwise
operators in Verilog.
Example 2.7
This example performs bitwise | operation on two 4-bit numbers A ¼ 4 0 b1011 and
B ¼ 4 0 b0011 . The Verilog expression computes a 4-bit C :
assign C = A | B;
performs the OR operation on corresponding bits of A and B and the operation is equivalent to:
C[0] = A[0] | B[0]
C[1] = A[1] | B[1]
C[2] = A[2] | B[2]
C[3] = A[3] | B[3]
2.6.3.9 Equality Operators
Equality operators are common to software programmers, but Verilog offers two flavors that are
specific to HW design: case equality (
). A simple equality operator
( ¼¼ ) checks whether all the bits of the two operands are the same. If any operand has an x or z as one
of its bits, the answer to the equality will be x . The
¼¼¼
) and case inequality (!
¼¼
as it also
matches x with x and z with z . The result of this operator is always a 0 or a 1 . There is a similar
difference between !
¼¼¼
operator is different from
¼¼
¼
and !
¼¼
. The following example differentiates the two operators.
Table 2.11 Bitwise arithmetic operators
Operator type
Operator symbol
Operation performed
Bitwise
Bitwise negation
&
Bitwise AND
&
Bitwise NAND
|
Bitwise OR
|
Bitwise NOR
^
Bitwise XOR
^ or ^
Bitwise XNOR
Search WWH ::




Custom Search