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 \n) to solve this.

Example:

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

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 \n\t"
"MOV R1, R2 \n\t"
"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:\n\t"
"MOV R1, R2\n\t"
"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 \n"
"foobar: \n\t"
"MOV R1, R2 \n\t"
"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\n"
"bne 1f\n"
"cpsie i\n"
"1:\n"
:
: "r" (flags)
: "memory");
}

Now try compiling with IAR compiler:

$ iccarm --thumb test.c

   IAR ANSI C/C++ Compiler V6.40.2./W32 for ARM
Copyright - IAR Systems AB. asm volatile(
^
"C:\home\NuttX\nuttx\test.c", Error[Og010]: Inline assembler instruction
does not have a unique size: " bne ?1_0" Errors:
Warnings: none

Any ideas what is going wrong?

If I change the "bne 1f\n" to "bne 1\n", 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\n"

Or in context:

void irqrestore(int flags)
{
asm volatile(
"tst %0, #1\n"
"bne.n 1f\n"
"cpsie i\n"
"1:\n"
:
: "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.

IAR EWAR 内联汇编 Error[Og010], Error [Og005], Error [Og006]的更多相关文章

  1. IAR EWAR 内联汇编 调用外部函数 Error[Og005], Error[Og006]

    How do I call a C function in another module from inline assembler in IAR EWARM? I have a bit of ass ...

  2. x86平台转x64平台关于内联汇编不再支持的解决

    x86平台转x64平台关于内联汇编不再支持的解决     2011/08/25   把自己碰到的问题以及解决方法给记录下来,留着备用!   工具:VS2005  编译器:cl.exe(X86 C/C+ ...

  3. 推荐一篇讲arm架构gcc内联汇编的文章

    这是来自ethernut网站的一篇文章,原文链接: http://www.ethernut.de/en/documents/arm-inline-asm.html 另外,据说nut/os是个不错的开源 ...

  4. GNU C 内联汇编介绍

    GNU C 内联汇编介绍 简介 1.很早之前就听说 C 语言能够直接内嵌汇编指令.但是之前始终没有去详细了解过.最近由于某种需求,看到了相关的 C 语言代码.也就自然去简单的学习了一下如何在 C 代码 ...

  5. 最牛X的GCC 内联汇编

    导读 正如大家知道的,在C语言中插入汇编语言,其是Linux中使用的基本汇编程序语法.本文将讲解 GCC 提供的内联汇编特性的用途和用法.对于阅读这篇文章,这里只有两个前提要求,很明显,就是 x86 ...

  6. C内联汇编

    用C写程序比直接用汇编写程序更简洁,可读性更好,但效率可能不如汇编程序,因为C程序毕竟要经由编译器生成汇编代码,尽管现代编译器的优化已经做得很好了,但还是不如手写的汇编代码.另外,有些平台相关的指令必 ...

  7. Linux 中 x86 的内联汇编

    工程中需要用到内联汇编,找到一篇不错的文章,趁机学习下. 原文地址:http://www.ibm.com/developerworks/cn/linux/sdk/assemble/inline/ 如果 ...

  8. GCC内联汇编入门

    原文为GCC-Inline-Assembly-HOWTO,在google上可以找到原文,欢迎指出翻译错误. 中文版说明 由于译者水平有限,故译文出错之处,还请见谅.C语言的关键字不译,一些单词或词组( ...

  9. C语言的本质(32)——C语言与汇编之C语言内联汇编

    用C写程序比直接用汇编写程序更简洁,可读性更好,但效率可能不如汇编程序,因为C程序毕竟要经由编译器生成汇编代码,尽管现代编译器的优化已经做得很好了,但还是不如手写的汇编代码.另外,有些平台相关的指令必 ...

随机推荐

  1. HTTP 错误 404.0 - Not Found

    当网上的那些修改程序池的方法,无法解决此问题时,可以尝试修改以下的参数: 1.控制面板-->程序-->启用或关闭Windows功能--> Internet Information S ...

  2. 02 uni-app框架学习:设置全局样式统一每个页面的背景颜色

    1.设置全局样式可以在App.vue里面 2.在每个页面的根view 里添加一个class名叫page

  3. MapReduce--shuffle

    一.Shuffle简介 Shuffle的正常意思是洗牌或弄乱,shuffle的大致范围就是把map task的输出结果有效的传送到Reduce端.也可以这样理解,shuffle描述着数据从map ta ...

  4. ecshop 2.7.x 批量测试

    下面为测试是否存在漏洞的脚本: sub MAIN($url) { use HTTP::UserAgent; my $r = HTTP::Request.new(); $r.uri: $url~'/us ...

  5. linux系统基本排查

    1.查看内存使用情况 free -g 当观察到free栏已为0的时候,表示内存基本被吃完了,那就释放内存吧. 释放内存: sync echo 3 > /proc/sys/vm/drop_cach ...

  6. ApiCloud开发经验总结

    1. 引擎或模块问题:遇到应用层无法解决的问题,如果能确定需要引擎和模块支持的,不要自己想办法绕过去,要第一时间在开发者社区提交问题,或找APICloud项目经理提出. !!!注意!!!: 在开发者社 ...

  7. MySQL 获得当前日期时间\时间戳 函数

    MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间(date + time)函数:now() mysql> select now(); +———————+ | now() | +—— ...

  8. mybatis,genarate自动生成代码

    ---恢复内容开始--- generatorConfig.xml配置文件: <?xml version="1.0" encoding="UTF-8"?&g ...

  9. 【Java】 大话数据结构(16) 排序算法(3) (堆排序)

    本文根据<大话数据结构>一书,实现了Java版的堆排序. 更多:数据结构与算法合集 基本概念 堆排序种的堆指的是数据结构中的堆,而不是内存模型中的堆. 堆:可以看成一棵完全二叉树,每个结点 ...

  10. 给定一种 pattern(模式) 和一个字符串 str ,判断 str 是否遵循相同的模式。 这里的遵循指完全匹配,例如, pattern 里的每个字母和字符串 str 中的每个非空单词之间存在着双向连接的对应模式。

    这个是LeetCode上的一道题目.本机上运行时正确的,但是LeetCode上显示是错误的,所以没有办法了只能记录在博客上了. 我的想法是先把pattern和str都转化成数组.例如"abb ...