Why x86 Zeroes a Register With `xor eax, eax`

Why x86 Zeroes a Register With xor eax, eax If you have ever disassembled a program - even a trivial one - you have almost certainly seen this line: xor eax , eax It looks like a riddle. The instruction says "XOR the eax register with itself," but what it actually means is "set eax to zero." In optimized code, compilers and assembly programmers commonly reach for it instead of the more obvious:…