Arithmetic and Logical Expressions.

As mentioned above, arithmetic expressions may contain the operators +, -, *, and /. In addition unary plus and minus are allowed. Note that the division operator is integer division. The operator "%" can be used to obtain remainders. Thus 5%2 would give the value 1. Exponentiation can be performed by using the exponentiation operator, **.

The comparison operators '<, '>, '<=, '>=, '==, and '!= can be used in arithmetic expressions. These operators return 0 for a false condition and 1 for a true. The operators &&, || and ! may also be used in arithmetic expressions. The binary operator && gives the value 0 if either of its operands is zero, and the value 1 otherwise. The binary operator || gives the value 0 if both of its operands are zero, and the value 1 otherwise. The unary operator ! gives the value 1 if its operand is zero and the value 0 otherwise.

All numbers and integer variables are represented as 32-bit binary numbers. There are a number of bit-level operations that can be performed on numbers and integer variables. The operator "&" returns the bitwise AND of its two operands, while the operator "|" returns the bitwise OR. The unary operator "~" returns the bitwise complement (ones complement) of its operand. The binary operator "^" returns the bitwise EXCLUSIVE OR of its operands. The binary operators ">>" and "<<" perform right and left shifts respectively. The left-hand operator is shifted the number of bits specified by the right-hand operator. Examples are 'x>>2 and 'y<<3. Either operand may be an expression.

The normal operator precedence for arithmetic operators is given below in low to high order. Operators listed on the same line are of equal precedence. Normal precedence can be overridden with parenthesis.

||, |, ^
&&, &
!, ~
'<, '>, '==, '<=, '>=, '!=
<<, >>
+, -
*, /, %
**
unary +, unary -

The evaluation of expressions containing the operators +, -, *, /, &, |, and ! may sometimes give unexpected results. Because these operators are also used by other FHDL parsers, the macro preprocessor makes an effort not to evaluate expressions that appear to be expressions that appear to be expressions for other parsers. For example, the expression abc+def, which is probablly a ROM/PLA preprocessor expression, will not be evaluated. Instead it will be treated as the string “abc+def”. If the macro preprocessor were to evaluate this expression, it would first coerce the strings abc and def to ingegers and then add the integers. Sinc non-numeric strings coerce to the value zero, this would produce the value zero for the expression. If this is indeed a ROM/PLA preprocessor expression, the results would be disasterous. Although the macro processor will probably guess right in virtually all cases, it is theoretically possible for errors to be made. To force the macro processor to treat the addition as a ROM/PLA expression, replace the plus sign with #”+”#. To force the macro processor to evaluate the addition regardless of the types of its operands, replace the plus sign with ‘+. The same rules apply to the other six operators.