zoukankan      html  css  js  c++  java
  • IAR EWAR 内联汇编 Error[Og010], Error [Og005], Error [Og006]

    Error [Og005] + [Og006] when using inline assembler

    EW targets: 430, ARM, AVR
    EW component: C/C++ compiler
    Last update: April 3, 2013

    Problem:

    When compiling a project with the IAR Embedded Workbench AVR v 6.12 the following errors might appear:

    Error[Og005]: Unknown symbol in inline assembly:

    Error[Og006]: Syntax error in inline assembly: "Error[54]: Expression can not be forward"

    Solution:

    Labels must be referred in the same assembler statement as they are declared.

    Use multiline inline assembler (with row breaks ) to solve this.

    Example:

    asm( "st     -Y,   R20    
    "
         "spmloop:            
    "
         "lN      R20, 0x37   
    "
         "SBRC    R20, 0      
    "
         "RJMP    spmloop     
    "
         "OUT     0x37,R25    
    "
         "SPM                 
    "
         "LD       R20,Y+     
    ");

    The behavior was not correct in earlier versions of the compiler platform.

    The new release uses a new internal compiler platform which is a bit more strict. 

    For the 5.5x and later versions of their compiler, IAR changed the rules for inline assembly such that you can no longer do things like this:

    asm("foobar:");
    asm("MOV R1, R2");
    asm("JMP foobar");

    You get an error message like

    unknown symbol in inline assembly

    The fix will be to tidy up the parts of the WISP firmware that have asm statements referencing labels created in other asm statements.

    Where possible, collapse runs of asm statements into one. The above would become:

    // oh yeah, and use volatile
    asm volatile ("foobar      
    	" 
                  "MOV R1, R2  
    	"
                  "JMP foobar");

    I've tested a patch that is backward compatible with IAR 5.4x and will merge it shortly.

    The patch for IAR 5.5x is ready; check out the iar550 branch.

    I'm trying to get someone to test that branch against IAR 5.4x; then I'll merge the patch into master.

    I got an error with both the volatile keyword and the label using the kickstarter version of IAR (5.52).

    This code compiles correctly,

    asm(
    "foobar:
    	"
    "MOV R1, R2
    	"
    "JMP foobar"
    );

    Note the addition of the colon.

    Volatile still causes an error.

    Also not that if we wanted to have code before the label,

    we would have to make sure the label is on the left margin:

    asm(
    "ADD R1, R2 
    "
    "foobar: 
    	"
    "MOV R1, R2 
    	"
    "JMP foobar"
    );

    or else IAR doesn't recognize it as a label.

    Thanks for those extra details.

    You are right that volatile is a no-no and

    that labels need special formatting (left justification and trailing colon);

    my original suggestion in the first comment was incorrect.

    I am about to merge the iar550 branch into master;

    it already incorporates these corrections.

    “Inline assembler instruction does not have a unique size” ARM Thumb-2 IAR

    I am having a problem with inline assembly with the IAR compiler for ARM, Cortex-M4.

    Here is a simple example of my problem; put the following code in a file, say, named test.c

    void irqrestore(int flags)
    {
      asm volatile(
          "tst    %0, #1
    "
          "bne    1f
    "
          "cpsie  i
    "
          "1:
    "
          :
          : "r" (flags)
          : "memory");
    }

    Now try compiling with IAR compiler:

    $ iccarm --thumb test.c
    
       IAR ANSI C/C++ Compiler V6.40.2.53884/W32 for ARM
       Copyright 1999-2012 IAR Systems AB.
    
        asm volatile(
        ^
    "C:homeNuttX
    uttx	est.c",6  Error[Og010]: Inline assembler instruction
              does not have a unique size: "        bne    ?1_0"
    
    Errors: 1
    Warnings: none

    Any ideas what is going wrong?

    If I change the "bne 1f " to "bne 1 ", it compiles fine, but I'm not sure if it is correct.

    Answer: From IAR, I was told (and have confirmed) that the following is the correct syntax:

     "bne.n  1f
    "

    Or in context:

    void irqrestore(int flags)
    {
      asm volatile(
          "tst    %0, #1
    "
          "bne.n    1f
    "
          "cpsie  i
    "
          "1:
    "
          :
          : "r" (flags)
          : "memory");
    }

    So, the IAR compiler's inline assembler is unable to determine the branch length.

    gcc-4.8 handles this withgcc -mthumb -O3 -c foo.c -o foo.o (and other options).

    There is no need to specify the specific branch type. 

  • 相关阅读:
    51nod 1050 循环数组最大子段和
    51nod 1183 编辑距离
    百度之星初赛一 补题
    jquery click嵌套 事件重复注册 多次执行的问题
    Shell变量赋值语句不能有空格
    Linux得到某个文件夹内文件的个数
    Ubuntu14.04下sogou输入法的输入框只显示英文不显示中文的问题
    Eclipse中mybatis的xml文件没有提示,出现the file cannot be validated as the XML definition.....
    整理一下postgresql的扩展功能postgis和pgrouting的使用
    Windows应用程序未响应
  • 原文地址:https://www.cnblogs.com/shangdawei/p/4612658.html
Copyright © 2011-2022 走看看