逻辑和按位操作符
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<div align=center><img width="250" height="250" src="/img/bitwise_logical.jpg"></div>
verilog中分为逻辑运算符和按位逻辑运算符。如上图,a、b都是3bit输入数据,按位操作后还是3位,但逻辑运算后就只有一位。
上图的代码如下:
'module top_module
'(
'input [2:0] a,
'input [2:0] b,
'output [2:0] out_or_bitwise,
'output out_or_logical,
'output [5:0] out_not
');
'assign out_or_bitwise = a | b; --按位运算
'assign out_or_logical = a || b; --逻辑运算
'assign out_not = {~b, ~a};
'endmodule
还包括逻辑与:&&, 按位与 &,等等