2
votes

I was reading the Intel manual, vol. 2A.

Compares the value in the AL, AX, EAX, or RAX register with the first operand (destination operand). If the two values are equal, the second operand (source operand) is loaded into the destination operand. Otherwise, the destination operand is loaded into the AL, AX, EAX or RAX register. RAX register is available only in 64-bit mode.

What is the purpose of loading the destination in the accumulator in case of a fail?

1

1 Answers

4
votes

It's a convenience so you don't have to do this yourself. You typically use cmpxchg in a loop, where you calculate a new value based on the current one. In case of failure, you will probably need the current value to recalculate and try again.