Quiz Entry - updated: 2026.07.06
What is the xor %eax, %eax idiom?
It zeroes %eax (anything XORed with itself is 0) — smaller and faster than mov $0, %eax, and it also clears the upper half of %rax.
xor %eax, %eax
Any value XORed with itself is zero. The CPU recognizes this special case and:
- Executes it with zero latency (register renaming)
- Clears dependency chains
- Is only 2 bytes (vs 5 bytes for
mov $0, %eax)
Bonus: On x86_64, writing to %eax automatically zeros the upper 32 bits of %rax. So xor %eax, %eax also zeros %rax.
Where you'll see it: Function prologues, before a loop accumulator, before call to set %eax = 0 (indicates no floating-point varargs to printf/sscanf).
Go deeper: