ARM Technical Support Knowledge Articles

ERRORS WITH IN-LINE ASSEMBLY

Applies to: RealView C Compiler

Answer


Information in this article applies to:


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

ATTACHED FILES

Request the files attached to this knowledgebase article.

Article last edited on: 2010-03-23 09:03:18

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential