Error [Og005] + [Og006] when using inline assembler
EW Targets: |
430, ARM, AVR |
EW Component: |
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 is not forward"
Solution:
Labels must is referred in the same assembler statement as they is 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 wasn't 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 so you can no longer d O things like this:
ASM ("foobar:"); ASM ("MOV R1, R2"); ASM ("JMP foobar");
You get a error message like
in inline assembly
The fix would be to tidy up the parts of the WISP firmware asm
that has statements referencing labels created I n Other asm
statements.
Where possible, collapse runs of asm
statements into one. The above would become:
and Use volatileasm volatile ("foobar \n\t"" MOV R1, R2 \n\t" JMP foobar");
I ' ve tested a patch that's backward compatible with IAR 5.4x and would merge it shortly.
The patch for IAR 5.5x was 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 the 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 and if we wanted to has code before the label,
We would have the sure the label are 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 were 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 is incorrect.
I am about to merge the iar550 branch into master;
It already incorporates these corrections.
"Inline assembler instruction does not has a unique size" ARM Thumb-2 IAR
I am have a problem with inline assembly with the IAR compiler for ARM, CORTEX-M4.
Here are a simple example of my problem; Put the following code in a file, say, named TEST.c
voidIrqrestore (intflags) {ASMvolatile( "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.53884/w32 forARM Copyright1999- -IAR Systems AB. ASMvolatile( ^"C:\home\NuttX\nuttx\test.c",6error[og010]: Inline assembler instruction does not has a unique size:"bne? 1_0"Errors:1Warnings: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's correct.
Answer:from IAR, I was told (and has confirmed), the following is the correct syntax:
" BNE.N 1f\n"
Or in Context:
voidIrqrestore (intflags) {ASMvolatile( "TST%0, #1 \ n" " BNE.N1f\ n " "Cpsie i\n" " 1:\ n" : : "R"(Flags):"Memory");}
So, the IAR compiler ' s inline assembler are unable to determine the branch length.
gcc-4.8 handles this with gcc -mthumb -O3 -c foo.c -o foo.o
(and other options).
There is no need to specify the specific branch type.
IAR Ewar inline Assembler error[og010], error [Og005], error [Og006]