📅  最后修改于: 2021-01-11 14:42:54             🧑  作者: Mango
运算符对表达式中的一个或多个操作数执行运算。表达式将操作数与适当的运算符组合在一起以生成所需的函数表达式。
对于FPGA,除法和乘法非常昂贵,有时我们无法合成除法。如果将Z或X用作值,则结果未知。这些操作将值视为无符号。
Character | Operation performed | Example |
+ | Add | b + c = 11 |
– | Subtrac | b – c = 9, -b=-10 |
/ | Divide | b / a = 2 |
* | Multiply | a * b = 50 |
% | Modulus | b % a = 0 |
每一位被操作,结果是最大操作数的大小,较小的操作数保留零并扩展到较大的操作数的大小。
Character | Operation performed | Example |
~ | Invert each bit | ~a = 3’b010 |
& | And each bit | b & c = 3’b010 |
| | Or each bit | a | b = 3’b111 |
^ | Xor each bit | a ^ b = 3’b011 |
^~ or ~^ | Xnor each bit | a ^~ b = 3’b100 |
这些运算符将向量减少到只有一位。如果存在字符z和x,则结果可以是已知值。
Character | Operation performed | Example |
& | And all bits | &a = 1’b0, &d = 1’b0 |
~& | Nand all bits | ~&a = 1’b1 |
| | Or all bits | |a = 1’b1, |c = 1’bX |
~| | Nor all bits | ~|a= 1’b0 |
^ | Xor all bits | ^a = 1’b1 |
^~ or ~^ | Xnor all bits | ~^a = 1’b0 |
这些运算符比较操作数,并得出1位标量布尔值。大小写相等和不等式运算符可用于未知或高阻抗值(z或x),如果两个操作数未知,则结果为1。
Character | Operation performed | Example |
> | Greater than | a > b = 1’b0 |
< | Smaller than | a < b = 1’b1 |
>= | Greater than or equal | a >= d = 1’bX |
<= | Smaller than or equal | a <= e = 1’bX |
== | Equality | a == b = 1’b0 |
!= | Inequality | a != b = 1’b1 |
=== | Case equality | e === e = 1’b1 |
!=== | Case inequality | a !== d = 1’b1 |
这些运算符比较操作数,并得出1位标量布尔值。
Character | Operation performed | Example |
! | Not true | !(a && b) = 1’b1 |
&& | Both expressions true | a && b = 1’b0 |
|| | One ore both expressions true | a || b = 1’b1 |
这些运算符向右或向左移动操作数,大小保持不变,移位的位丢失,向量用零填充。
Character | Operation performed | Example |
>> | Shift right | b >> 1 results 4?b010X |
<< | Shift left | a << 2 results 4?b1000 |
有三个赋值运算符,每个赋值运算符执行不同的任务,并与不同的数据类型一起使用:
这些是用于条件测试和创建向量的运算符。
Character | Operation performed | Example |
?: | Conditions testing | test cond. ? if true do this or if not do this |
{} | Concatenate | c = {a,b} = 8’101010×0 |
{{}} | Replicate | {3{2’b10}}= 6’b101010 |
表的顺序告诉您首先要执行的操作。第一个具有最高优先级。 ()可用于覆盖默认值。
Operators precedence |
---|
+, -, !, ~ (Unary) |
+,- (Binary) |
<<, >> |
<,>,<=,>= |
==, != |
& |
^, ^~ or ~^ |
| |
&& |
|| |
?: |