Why xor eax, eax?
10 days ago
- #x86-architecture
- #compiler-optimizations
- #assembly-programming
- XOR instruction is surprisingly common in x86 Linux desktop executions.
- Compilers use XOR to set registers to zero for efficiency.
- XOR eax, eax saves code space and execution time by utilizing CPU optimizations.
- Writing to 32-bit registers like eax zeros the top 32 bits of the 64-bit register.
- GCC and clang use 32-bit variants for extended registers like r8d for consistency.
- Compiler optimizations like these are part of a series on Advent of Compiler Optimisations 2025.