Difference between operator precedence in armasm and C

The assembler order of precedence is not exactly the same as in C.

For example, (1 + 2 :SHR: 3) evaluates as (1 + (2 :SHR: 3)) = 1 in armasm. The equivalent expression in C evaluates as ((1 + 2) >> 3) = 0.

You are recommended to use brackets to make the precedence explicit.

If your code contains an expression that would parse differently in C, and you are not using the --unsafe option, armasm normally gives a warning:

A1466W: Operator precedence means that expression would evaluate differently in C

Table 35 shows the order of precedence of operators in armasm, and a comparison with the order in C (see Table 36).

From these tables:

Table 35. Operator precedence in armasm

armasm precedenceequivalent C operators
unary operatorsunary operators
* / :MOD:* / %
string manipulationn/a
:SHL: :SHR: :ROR: :ROL:<< >>
+ - :AND: :OR: :EOR:+ - & | ^
= > >= < <= /= <>== > >= < <= !=
:LAND: :LOR: :LEOR:&& ||

Table 36. Operator precedence in C

C precedence
unary operators
* / %
+ - (as binary operators)
<< >>
< <= > >=
== !=
&
^
|
&&
||

Show/hideSee also

Copyright © 2010-2011 ARM. All rights reserved.ARM DUI 0473C
Non-ConfidentialID080411