How to use the earlyclobber inline assembly constraint

  • version

    1.0.1

  • scope

    Example.

    This code is provided as example code for a user to base their code on.

  • description

    How to use the earlyclobber inline assembly constraint

  • boards

    Unless otherwise specified, this example runs on the SliceKIT Core Board, but can easily be run on any XMOS device by using a different XN file.

Normally the compiler assumes all input operands are read before any of the output operands are written. If an input operand is unused after the asm statement the compiler may decide to place the input operand in the same register as one of the output operands.

The earlyclobber constraint modifier “&” can be used to specify that an output operand is modified before all input operands are consumed.

asm("or %0, %1, %2\n"
    "or %0, %0, %3\n"
    : "=&r"(a)
    : "r"(b), "r"(c), "r"(d));

The compiler will place the output operand in a different register to all the input operands.