int Math::test_iadd(int a, int { __asm volatile ( "add r0, %0, %1 \n\t" : : "r" (a), "r" ( : "r0" );}
int Math::test_iadd2(int a, int { int ret; __asm volatile ( "add %0, %1, %2 \n\t" : "=r" (ret) : "r" (a), "r" ( : "r0" ); return ret;}
I could be wrong, but I believe that this code does not actually guarantee that the output ends up in r0. The register identities in the assembler are symbolic rather than actual register names, and I'm not sure how they actually get resolved to real registers. It's the logical output however, so it happens to work.Your second function is certainly the way I would write the return code.
Yes, but you are assuming the compiler (which parses the inline assembler and can shove it through the optimizer) actually assigns the "real" r0 to the symbolic r0 in your program and hasn't reordered any of the instructions in the instruction stream.
returning the value in R0 is defined in the AAPCS