System Debug Reference Manual (32650-90888)
Chapter 2 31
User Interface
Operators
0 <= i MOD j < j.
The operation i MOD j, where j <= 0, is illegal.
Unary minus is also allowed, but note that the - operator must precede any base prefix
character for numeric literals. This means that
-#32767
is allowed, but
#-32767
is not.
Arithmetic operands are restricted to the classes INT and PTR. In general, the types of the
operands determine the result type of an arithmetic operation. In certain cases, one of the
operands may be converted to another type before the operation is performed (see the
following discussion).
Arithmetic on the INT Class
When both operands are of the INT class, the result of the arithmetic operation is also an
INT. The type of the result is the largest type of the two operands, unless this type is not
large enough to represent the result. In this case, the next larger type that can hold the
result is used. The order of the two operands does not affect the result type.
The INT types are shown below in order of size:
smallest
: S16, U16, S32, U32, S64 :
largest
The following examples illustrate the result types of some simple arithmetic operations.
2 + 5 = 7 1 + 65535 = 65536
(U16) (U16) (U16) (U16) (U16) (U32)
2 - 5 = -3 1 - 65535 = -65534
(U16) (U16) (S16) (U16) (U16) (S32)
Pointer Arithmetic
Arithmetic between a pointer and an integer is just like arithmetic between two integers,
except only the offset part of a pointer contributes to the operation. With short pointers,
only the (unsigned) low-order 30 bits are used. With long pointers, the entire 32-bit offset
is used, treated as a U32. With extended address pointers, the 64-bit offset is used. The
type of the result is that of the pointer, with the same bits that contributed to the
computation being replaced by the result. Negative results, and results that cannot be
represented with the available bits, cause an overflow condition.
The most common arithmetic operation between two pointers is subtraction, and the result
is of type S32 or S64. Other arithmetic operations may be performed between two pointers,
but both pointers, whether long, short or extended, must reference the same space IDs. As