- 论坛徽章:
- 0
|
cmpxchg
When AT&T syntax is used, the ‘cmpxchg’ instruction has this layout:
在AT&T中,cmpxchg的格式如下:
[lock] cmpxchg reg, reg/mem
其中[lock]是可选的,用于SMP 源操作数 目的操作数
依照intel的手册,cmpxchg还有两个隐式的参数,
一个是cpu的accumulator register
一个是cpu的EFLAGS register
其中accumulator register(又称为eax)即可以做源操作数,也可以做目的操作数;
而在EFLAGS register中的6个状态位将会因为指令的结果而被改变;
这个指令将accumulator和目的寄存器相比较(因此EFLAGS中的ZF-bit位也会相应的被修改)
其执行结果为:
If (accumulator == destination)
{ ZF <- 1; destination <- source; }
If (accumulator != destination)
{ ZF <- 0; accumulator <- destination; }
值得注意到是指令执行后accumulator %eax将会产生影响并发生作用;所以使用cmpxchg的时候要注意上下文。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/58901/showart_1883577.html |
|