I used netbeans in Windows 7 as my IDE. And below is my assembly code:
/* Atomic exchange (of various sizes) */
inline void *xchg_64(void *ptr, void *x)
{
__asm__ __volatile__("xchgq %0,%1"
:"=r" ((unsigned long long) x)
:"m" (*(volatile long long *)ptr), "0" ((unsigned long long) x)
:"memory");
return x;
}
When I compile my project, there’s one error occurs:
tklock.h:29:15: error: lvalue required in asm statement
And line 15 is:
:"memory");
How to fix the problem?
There is no way to directly exchange the values of two memory locations. Intel just hasn’t provided that kind of instructions.
You will have to code it as load-exchange-store using a register as an intermediary.
And in that case you could just as well code it in C…