xadd

Exchange and add

Exchanges the two operands, then stores their sum in the destination (first) operand.

486 and latertakes lock

Intel's reference: XADD

CFPFAFZFSFDFOF ●●●●●–●
  • ● set from the result
  • – not changed

Forms

Operands

r/m
A general-purpose register or memory location matching the operation’s size, for example rax or qword [rbp-8]. The byte registers ah, bh, ch and dh cannot be used with a REX prefix, including when the memory address uses r8–r15.
reg
A general-purpose register matching the operation’s size, for example al, ax, eax or rax. The byte registers ah, bh, ch and dh cannot be used with a REX prefix, which is required by spl, bpl, sil, dil and r8–r15.

This instruction can be used with a LOCK prefix for multi-processor synchronisation purposes.

global _start

section .text
_start:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        xadd rax, rbx

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall