3.6.11. Binary operators

Binary operators are written between the pair of subexpressions they operate on.

Binary operators have lower precedence than unary operators. Binary operators appear in this section in order of precedence.

Note

The order of precedence is not the same as in C, see Operator precedence.

Multiplicative operators

Multiplicative operators have the highest precedence of all binary operators. They act only on numeric expressions.

Table 3.5 shows the multiplicative operators.

Table 3.5. Multiplicative operators

Operator

Usage

Explanation

*

A*B

Multiply

/

A/B

Divide

MOD

A:MOD:B

A modulo B

String manipulation operators

Table 3.6 shows the string manipulation operators.

In the two slicing operators LEFT and RIGHT:

  • A must be a string

  • B must be a numeric expression.

In CC, A and B must both be strings.

Table 3.6. String manipulation operators

Operator

Usage

Explanation

LEFT

A:LEFT:B

The left-most B characters of A

RIGHT

A:RIGHT:B

The right-most B characters of A

CC

A:CC:B

B concatenated onto the end of A

Shift operators

Shift operators act on numeric expressions, shifting or rotating the first operand by the amount specified by the second.

Table 3.7 shows the shift operators.

Table 3.7. Shift operators

Operator

Usage

Explanation

ROL

A:ROL:B

Rotate A left by B bits

ROR

A:ROR:B

Rotate A right by B bits

SHL

A:SHL:B

Shift A left by B bits

SHR

A:SHR:B

Shift A right by B bits

Note

SHR is a logical shift and does not propagate the sign bit.

Addition, subtraction, and logical operators

Addition and subtraction operators act on numeric expressions.

Logical operators act on numeric expressions. The operation is performed bitwise, that is, independently on each bit of the operands to produce the result.

Table 3.8 shows addition, subtraction, and logical operators.

Table 3.8. Addition, subtraction, and logical operators

Operator

Usage

Explanation

+

A+B

Add A to B

-

A-B

Subtract B from A

AND

A:AND:B

Bitwise AND of A and B

OR

A:OR:B

Bitwise OR of A and B

EOR

A:EOR:B

Bitwise Exclusive OR of A and B

Relational operators

Table 3.9 shows the relational operators. These act on two operands of the same type to produce a logical value.

The operands can be one of:

  • numeric

  • program-relative

  • register-relative

  • strings.

Strings are sorted using ASCII ordering. String A is less than string B if it is a leading substring of string B, or if the left-most character in which the two strings differ is less in string A than in string B.

Arithmetic values are unsigned, so the value of 0>-1 is {FALSE}.

Table 3.9. Relational operators

Operator

Usage

Explanation

=

A=B

A equal to B

>

A>B

A greater than B

>=

A>=B

A greater than or equal to B

<

A<B

A less than B

<=

A<=B

A less than or equal to B

/=

A/=B

A not equal to B

<>

A<>B

A not equal to B

Boolean operators

These are the operators with the lowest precedence. They perform the standard logical operations on their operands.

In all three cases both A and B must be expressions that evaluate to either {TRUE} or {FALSE}.

Table 3.10 shows the Boolean operators.

Table 3.10. Boolean operators

Operator

Usage

Explanation

LAND

A:LAND:B

Logical AND of A and B

LOR

A:LOR:B

Logical OR of A and B

LEOR

A:LEOR:B

Logical Exclusive OR of A and B

Copyright © 2000, 2001 ARM Limited. All rights reserved.ARM DUI 0068B
Non-Confidential