Why I got this "Error[Ta087]: Register r8 not available to clobber in selected core/mode" on IAR EWARM

271 Views Asked by At

I am trying to compile an IAR project with mixed C and ASM for Cortex-M0, and I got an error of

Error[Ta087]: Register r8 not available to clobber in selected core/mode

when I have this line

: "r4", "r5", "r6", "r7", "r8"

But it compiles OK if I remove "r8" from above line. What is special about "r8" that makes it different from "r4~7"? I searched Cortex-M0 documents but was not able to find related info. I used "r8" in my ASM code, and if "r8" is not available to clobber, is it still safe to use "r8" in my ASM code?

1

There are 1 best solutions below

0
Michael M. On

To answer your first question:

There's nothing real special about r8 compared to r0-r7, except that some instructions only support the use of r0-r7 in Thumb mode due to how the instruction is encoded. The ARM Procedure Call Standard (AAPCS) provides information about the function of machine registers. (Jake 'Alquimista' LEE already pointed this out in comments.)

To answer your second question:

If you want to be sure that avoiding r8 in the clobber list is safe, you can take a look at the generated assembly code of the compiler and see if it is okay. But you'd probably need to check the surrounding asm every time you compile the code, to make sure the compiler isn't using it for something.

However, if you provide some more information like the IAR EWARM version and the whole extended inline assembly and more, we might tell you why IAR is complaining and how to improve the extended inline assembly to avoid the issue.

Since you're using registers in the clobbered list, I assume you are using registers directly in your inline assembly. I'd recommend to let the compiler choose the registers to use and use constraints to ensure only r0-r7 are used for specific instructions. This might even produce some more efficient code.

For example, use some dummy variables as "=r"(dummy1) output operands to let the compiler do register allocation. As GCC documents, when compiling for Thumb mode, "=r" is an alias for "=l", always picking a low register (r0-r7). If you can use a high register (r8-r15) in your asm, you can give the compiler that choice with "=hl"(dumm2), to give a choice of h (high reg) or l (low reg).