Question

When using inline assembly with XLC compiler (for powerpc) the labels are translated and as a result it is impossible to know the final label name for jumps. Example:

int main()
{
    __asm__("mylabel:");      
    __asm__("nop");
    __asm__("b mylabel");
}

If I compile the previous code using GCC, everything works as expected. However, when using XLC, the assembly generated is the following:

...
.L1
nop
b mylabel
...

Obviously, the program fails to compile because "mylabel" is never defined. The definition of "mylabel" is automatically translated to ".L1" name. Actually this name depends on the number of local labels defined. So, it can be ".L1", ".L2" ...

I tried using asm, __asm instead of __asm__ but I get the same output. Disabling compiler optimizations does not work either. Does anybody know how to keep local label names when generating assembly in XLC? Any other work-around will help too.

Thank you,

Was it helpful?

Solution

This says Branching to a label in another asm statement is not supported.

Try putting all of your inline assembly code into a single __asm__ statement something like:

    __asm__("mylabel:\n"
            "nop\n"
            "b mylabel");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top