7.32 Differences between expressions in embedded assembler and C or C++

There are a number of differences between embedded assembly and C or C++.

Specifically:

  • Assembly expressions are always unsigned. The same expression might have different values between assembly and C or C++. For example:

    MOV r0, #(-33554432 / 2)     // result is 0x7f000000
    MOV r0, #__cpp(-33554432 / 2)  // result is 0xff000000
    
  • Assembly numbers with leading zeros are still decimal. For example:

    MOV r0, #0700           // decimal 700
    MOV r0, #__cpp(0700)       // octal 0700 == decimal 448
    
  • Assembly operator precedence differs from C and C++. For example:

    MOV r0, #(0x23 :AND: 0xf + 1)    // ((0x23 & 0xf) + 1) => 4
    MOV r0, #__cpp(0x23 & 0xf + 1)   // (0x23 & (0xf + 1)) => 0
  • Assembly strings are not NUL-terminated:

    DCB "Hello world!"         // 12 bytes (no trailing NUL)
    DCB __cpp("Hello world!")         // 13 bytes (trailing NUL)

Note:

The embedded assembly rules apply outside __cpp, and the C or C++ rules apply inside __cpp.

Non-ConfidentialPDF file icon PDF versionARM DUI0472M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.