GCC's inline assembler recognizes the declarators =r
and =&r
. These make sense to me: the =r
lets the assembler reuse an input register for output.
However, GCC's inline assembler also recognizes the declarators +r
and +&r
. These make less sense to me. After all, isn't the distinction between +r
and +&r
a distinction without a difference? Does the +r
alone not suffice to tell the compiler to reserve a register for the sole use of a single variable?
For example, what is wrong with the following GCC code?
#include <stdio.h>
int main()
{
int a = 0;
printf("Initially, a == %d.\n", a);
/* The architecture is amd64/x86-64. */
asm(
"inc %[a]\n"
: [a] "+r" (a)
: : "cc"
);
printf("However, after incrementation, a == %d.\n", a);
return 0;
}
Notice incidentally that my inline assembly lacks an input declaration because, in my (perhaps mistaken) mind, the +r
covers input, clobbering, output, everything. What have I misunderstood, please?
BACKGROUND
I have programmed 8- and 16-bit microcontrollers in assembly a bit, but have little or no experience at coding assembly in a hosted environment.