当前位置: 技术问答>linux和unix
【在线等求助】spinlock模拟出错
来源: 互联网 发布时间:2016-10-14
本文导语: #include int mylock=0; void spinlock(int lock) { int locked=1; __asm__ __volatile__( "enter:movl %1 %%eax; cmpxchg %%eax %0; jz enter; " :"+m"(lock^0) :"m"(locked) :"memory","eax" ); return; } int main(int argc,char* argv[]) { printf("%d",mylock); spinlock(my...
#include
int mylock=0;
void spinlock(int lock)
{
int locked=1;
__asm__ __volatile__(
"enter:movl %1 %%eax;
cmpxchg %%eax %0;
jz enter;
"
:"+m"(lock^0)
:"m"(locked)
:"memory","eax"
);
return;
}
int main(int argc,char* argv[])
{
printf("%d",mylock);
spinlock(mylock);
printf("%d",mylock);
return 0;
}
出现下面的错误:
执行 g++.exe...
g++.exe "C:UsersLHJDesktop未命名1.cpp" -o "C:UsersLHJDesktop未命名1.exe" -I"C:Dev-Cppinclude" -L"C:Dev-Cpplib"
C:UsersLHJAppDataLocalTemp/ccD80V6U.s: Assembler messages:
C:UsersLHJAppDataLocalTemp/ccD80V6U.s:17: Error: junk `(%ebp)%eax' after expression
C:UsersLHJAppDataLocalTemp/ccD80V6U.s:17: Error: suffix or operands invalid for `mov'
C:UsersLHJAppDataLocalTemp/ccD80V6U.s:17: Error: junk `8(%ebp)' after register
执行结束
|
"enter:movl %1, %%eax;
cmpxchg %%eax, %0;
cmpxchg %%eax, %0;