美国电话电报公司 x86 | `xadd %eax, (%ecx)` 是做什么的?

AT&T x86 | What does `xadd %eax, (%ecx)` do?

是否交换 %eaxvalue stored at address%ecxx 并将总和存储在 address%ecx 中?

指令XADD ...

...Exchanges the first operand (destination operand) with the second operand (source operand), then loads the sum of the two values into the destination operand.

所以,根据它的操作,它执行以下微代码:

TEMP ← SRC + DEST;
SRC  ← DEST;
DEST ← TEMP;

在你的情况下,这意味着 xadd %eax, (%ecx)

  • 创建一个 TEMP 变量,其中包含 EAX 的值加上 ECX
  • 指向的地址处的值
  • ECX指向的地址的值移动到EAX
  • TEMP变量移动到ECX
  • 指向的地址

该指令可以与 LOCK 前缀组合,因此可以自动执行。