here is a C function that used extend assembly code in it:
static inline uint
xchg(volatile uint *addr, uint newval)
{
uint result;
asm volatile("lock; xchgl %0, %1" :
"+m" (*addr), "=a" (result) :
"1" (newval) :
"cc");
return result;
}
I read this codeproject link for learn how to use Extended Assembly in C code but I confused at this code.
I don't understand something in this code :
1) where is (newval)
used as input in assembly code ? (%0
is refer to (*addr)
and %1
is refer to (result)
right ? then "1" (newval)
never used in the code (we never see %2
in code). or I am wrong ? )
2) what is "1"
in "1" (newval)
in input operands ?
3) what is "+m"
sign means in "+m" (*addr)
?
All the answers of your questions about GCC asm
can be from from 6.41 Assembler Instructions with C Expression Operands and 6.42 Constraints for asm Operands.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With