|
|
|
|
|
|
|
|
|
|
|
|
Operations on logic and bit types
|
|
|
When a binary operator has one operand of type bit and another of type logic, the result is of type logic. If one operand is of type int and the other of type integer, the result is of type integer. The operators != and == return an X if either operand contains an X or a Z, as in Verilog-2001. This is converted to a 0 if the result is converted to type bit, e.g. in an if statement. The unary reduction operators (& ~& | ~| ^ ~^) can be applied to any integer expression (including packed arrays). The operators shall return a single value of type logic if the packed type is four valued, and of type bit if the packed type is two valued. |
|
|
|
|
|
Example : Logic and bit
|
|
|
|
|
|
1 module bit_logic_operator ();
2
3 bit [7:0] a = 8'b01xz_01xz;
4 logic [7:0] b = 8'b01xz_01xz;
5 integer c = 32'b01xz_01xz_01xz_01xz;
6 int d = 32'b01xz_01xz_01xz_01xz;
7
8 initial begin
9 $display ("Value of bit a = %b", a);
10 $display ("Value of logic b = %b", b);
11 $display ("Value of integer c = %b", c);
12 $display ("Value of int d = %b", d);
13 $display (" bit + integer = %b", a + c);
14 $display (" logic + int = %b", b + d);
15 a = 10;
16 b = 20;
17 c = 30;
18 d = 40;
19 $display (" bit + logic = %b", a + b);
20 $display (" integer + int = %b", c + d);
21 end
22
23 endmodule
You could download file bit_logic_operator.sv here
|
|
|
|
|
|
Simulator Output |
|
|
|
|
|
Value of bit a = 01000100
Value of logic b = 01xz01xz
Value of integer c = 000000000000000001xz01xz01xz01xz
Value of int d = 00000000000000000100010001000100
bit + integer = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
logic + int = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
bit + logic = 00011110
integer + int = 00000000000000000000000001000110
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|