Keil Logo

ARMCC: ERRORS WITH IN-LINE ASSEMBLY


Information in this article applies to:

  • RealView Compiler Version 3.0 or higher

QUESTION

I am trying to use the embedded in-line assembler of the RealView Compiler but I am getting errors with the following function:

int func (int val)  {
__asm
    {
    MOV R7,0xFFFF0000
    MOV R0,R0,LSL #16
        ADD R0,R0,R1
    }

        return val;
}

The errors are:

warning:  #1267-D: Implicit physical register R7 should be defined as a variable
warning:  #1267-D: Implicit physical register R0 should be defined as a variable
error:  #549: variable "R0" is used before its value is set
warning:  #1267-D: Implicit physical register R1 should be defined as a variable
error:  #549: variable "R1" is used before its value is set
warning:  #177-D: variable "val2" was declared but never referenced

What is wrong with my code?

ANSWER

Instead of accessing registers you should use variables. The in-line assembler allows you to access register variables directly with names and dynamically assigns them to correct and valid CPU registers. In this way it is even possible to use code optimizations together with in-line assembly and the compiler does not require to reduce the code optimization when in-line assembly is used.

When you re-write you code as follows everything will be just fine:

int func (int val)  {
  int val2;

__asm
    {
    MOV val2,0xFFFF0000
    MOV val,val,LSL #16
    }
  return val+val2;
}

MORE INFORMATION

SEE ALSO

Last Reviewed: Sunday, January 29, 2017


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.