I'm trying to port some code from GCC to IAR in an attemp to free up some space. The target is an ATtiny26. The problem I'm having is a delay function that was modeled after the 4 cycle delay in GCC's delay.h file.
The following four instructions give errors and I can't figure out why:
asm("BRNE -0x02 "); asm("BRNE -2 "); asm("BRNE 0xFE "); asm("BRNE -0xFE");
The errors that they give include the following (with some variation for each of the 4 lines of course):
Error[Og006]: Syntax error in inline assembly: "Error: PC offset out of range. Valid range is -128 (-0x80) to 126 (0x7E)."
Error[Og010]: Inline assembler instruction does not have a unique size: "BRNE -0x02 "
When I look at GCC's disassembly in AVRStudio, I see BRNE -0x02. The syntax may be different in IAR, but for the life of me I can't figure out how it decide that -2 is not inside the range of -126 to +126, and I can't think of any other ways to write -2.
Also, I've included the following in a file named 'delay.asm'
NAME delay_us PUBLIC delay_us RSEG CODE delay_us: sbiw R24,1 brne delay_us ret END
In my main.h file I have the line "extern void delay_us( uint16_t count );"
I have included the delay.asm file in my project, I can right click and compile it (compiles to 6 bytes) . The list file doesn't show exactly what its doing as it is saying "brne label" instead of "brne xxxx" so I don't know what it considers acceptable assembly. But what it does show is the hex value "F7F1" which I believe is machine code, and it also matches what AVRStudio displayes from the GCC compiled code.
But when I try to link the files (they both compile fine, just won't link) I get the following error:
Error[e46]: Undefined external "delay_us" referred in main ( O:\Atmel Code\IAR\Printer Presenter\Release\Obj\main.r90 )
I've read as many posts on this forum about this topic that I could find, and I did find one topic that was incredibly close to this one. It helped me get the .asm file, but not get rid of the undefined extern problem. And while the documentation for the IAR compiler looks nice, it so far has been less than helpful.