29.3.1.1. x86 CMPXCHG instruction

CMPXCHG: compare and exchange. cmpxchg a, b does:

if (RAX == b) {
    ZF = 1
    b = a
} else {
    ZF = 0
    RAX = b
}