Bitwise operator
Verilog Bitwise Operator |
There are four basic types of Bitwise operators as listed in the following table.
Table: A one bit comparator
Bitwise Operator | Symbol | Example |
AND | & | assign c = a & b ; |
OR | | | assign z = x | y; |
NOT | ~ | assign x_ = ^x; |
XOR | ^ | assign r = p ^ q ; |
It is possible to generate sigle assign statement that uses a combination of these bitwise operators, poosibly using parenthesis. As an example, we had already used a one bit comparator using the assignement statement
assign z = (~x & ~y) |(x & y);
Operation on Vectors |
Bitwise operations can be performed on vectors without refering to its individual bits. As an example
wire [1:0] x,y, z;
The statement
assign z = x | y;
is same as
assign z[0] = x[0] | y[0]; assign z[1] = x[1] | y[1];
|
This example does the same fuction as the previous example, but we have used primitive gates in this example. Notice how the verilog code gets simplified by the use of the udp tables/
Explanation |
A new primitive is defined using the primitive keyword. It has an output and a list of inputs as its argument.
|
The definition of the primitive is followed by a table definition. The Table definition starts with keyword table and ends with keyword endtable
|
Inside the table definition we define the primitive behavior with a number of rows. Each row has values of the inputs separated by whitespaces, followed by semicolon, followed by the output. The input values should be in the same sequence as defined in the premitive definition.
Finally the prenitive definition ends with the keyword endpremitive.
We can instantiate the primitive with the primitive name followed by and identifier name and a list of the out and inputs as in
compare c0(z, x, y);
The stimulus stays the same and it produces the same result.
|
And it produces the same output
x=0,y=0,z=1
x=1,y=0,z=0
x=1,y=1,z=1
x=0,y=1,z=0