Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

x86

att

Does it exchange %eax and value stored at address%ecxx and store the sum in address%ecx?

like image 536
Daksh Shah Avatar asked Oct 23 '25 01:10

Daksh Shah


1 Answers

The instruction 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.

So, according to its Operation, it executes the following microcode:

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

In your case this means that xadd %eax, (%ecx)

  • Creates a TEMP variable containing the addition of the value of EAX plus the value at the address pointed to by ECX
  • Moves the value at the address pointed to by ECX to EAX
  • Moves the TEMP variable to the address pointed to by ECX

This instruction can be combined with a LOCK prefix and hence be executed atomically.

like image 50
zx485 Avatar answered Oct 24 '25 17:10

zx485