Arithmetic Operators in Boolean Expressions (AHDL)

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

Note: The * operator is supported for Boolean expressions by the Quartus II software only; this operator is not supported for Boolean expressions by the MAX+PLUSII software.

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:

Note: When you add two groups together on the right of a Boolean equation with the + operator, you can place a 0 on the left of each group to sign-extend the width of the group. This method provides an extra bit of information to the group on the left of the equation that can be used as a carry-out signal.
  • Unlike the result width of the * operator in other Hardware Description Languages (HDLs) such as Verilog HDL, the result width of the * operator in AHDL is equal to the width of one of the operator's operands, and not to the sum of the operator's operands. This difference in the result width may introduce subtle problems with expressions such as result[7..0] = a[3..0] * b[3..0], where the full 8 bits of the multiplication operation are not assigned to result[]; instead, the lower four bits of the multiplication operation are assigned to both result[7..4] and result[3..0].

    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.

  • You can name Boolean operators and comparators in AHDL files to make it easy to enter resource assignments and to interpret the Equations Section of the Text-Format Report File (.rpt) or HTML-Format Report File (.htm).
  • The arithmetic operators that are supported in Boolean expressions are a subset of the arithmetic operators supported in arithmetic expressions.