Arithmetic operators are used to perform arithmetic addition, subtraction, and multiplication operations on groups and numbers in AHDL Boolean expressions. The following arithmetic operators are used in Boolean expressions:
Operator |
Example |
Description |
---|---|---|
+ (unary) |
+1 |
positive |
- (unary) |
-a[4..1] |
negative |
+ |
count[7..0] + delta[7..0] |
addition |
- |
rightmost_x[] - leftmost_x[] |
subtraction |
* |
c[] = a[] * b[]; |
multiplication |
The unary plus (+) and minus (-) are prefix operators. The + operator does not affect its operand, but you may use it for documentation purposes (that is, to indicate a positive number). The - operator interprets its operand as a binary representation of a number if it is not already a number. It then performs a two's complement unary-minus operation on the operand.
The following rules apply to the other arithmetic operators:
To use the full result width from the multiplication operation, place a 0 on the left of each group, for example, result[7..0] = (0, a[3..0]) * (0, b[3..0]), or use the lpm_mult megafunction instead of the * operator to perform multiplication operations.