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)
?
关于GCC asm
所有问题的答案可以来自6.41具有C表达式操作数的汇编程序指令和用于asm操作数的6.42约束 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.