This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Inline Assembly Parameter example in Definitive guide to Cortex M0/M0+

I was reading The Definitive Guide to ARMCortexM0/M0+ by  

In Chapter 21, under section 21.4.2 GNU Compiler Collection, there is a example function with inline assembly operation:

int my_mul_10(int DataIn)
{
  int DataOut;
    __asm("   movs  r0, %0\n"
          "   movs  r3, #10\n"
          "   mul   r0, r3\n"
          "   movs  %1, r0\n"
          :"=r" (DataOut) : "r" (DataIn) : "cc", "r0", "r3");
  return DataOut;
}



And with the following explanation:

In the code example, %0 is the first input parameter and %1 is the first output parameter. Since the operand order is output _operands, input_operands, and clobbered_operands, “DataOut” is assigned to %0, and “DataIn” is assigned to %1. Since the code changes register R3, it needs to be added to the clobbered operand list.

Shouldn't "DataOut" is assigned to %1 and "DataIn" to %0?

Or am I missing something here?

Parents
  • Sorry for the error in the text, and a bit unclear in the descriptions.

    In the code:

    1st parameter (%0) : "=r" (DataOut)

    2nd parameter (%1): "r" (DataIn)

    3rd to 5th parameters: "cc", "r0", "r3"

    Thomas's is correct - the first sentence is wrong, and might be clearer to write it as:

    "In the code example, %0 is the output parameter and %1 is the input parameter."

    Please note that this is an old style inline assembler format. Recent gcc support symbolic names - instead of using %0, %1..., you can use %[ _name_ ] which is much easier to read. Unfortunately I wasn't aware of this when I wrote the book.

    regards,

    Joseph

Reply
  • Sorry for the error in the text, and a bit unclear in the descriptions.

    In the code:

    1st parameter (%0) : "=r" (DataOut)

    2nd parameter (%1): "r" (DataIn)

    3rd to 5th parameters: "cc", "r0", "r3"

    Thomas's is correct - the first sentence is wrong, and might be clearer to write it as:

    "In the code example, %0 is the output parameter and %1 is the input parameter."

    Please note that this is an old style inline assembler format. Recent gcc support symbolic names - instead of using %0, %1..., you can use %[ _name_ ] which is much easier to read. Unfortunately I wasn't aware of this when I wrote the book.

    regards,

    Joseph

Children