April 22, 2026
When zero sparks a code war
XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
Programmers are fighting over the ‘right’ way to write the number zero
TLDR: A deep‑dive on why programmers use one specific instruction to write the number zero turns into a surprisingly heated debate over speed, style, and tradition. Commenters compare it to evolution, diet soda, and racing slogans, proving even the number 0 can split the tech world into camps.
A tiny nerd detail just triggered a full-on identity crisis in the programming world: what’s the proper way to reset a computer register to zero – using XOR or SUB? The original article calmly explains that xor eax, eax became the popular way because it’s short, efficient, and compilers loved it, so humans copied them like fashion influencers. But in the comments, the crowd turns it into a tribal war over one single number: 0.
One commenter gushes that the author somehow makes the “most mundane aspects of computing” fun, while another drops the Ricky Bobby line, “If you’re not first, you’re last,” to explain how XOR won: it got a tiny early lead and never looked back. Then a self-confident hardware fan crashes in to declare the “obvious answer” is that XOR is faster and starts lecturing about how subtraction has to ripple a “carry bit” through all the ones and zeros, igniting quiet eye-rolls from people who know modern chips are more complicated than that.
Other nerds flex their obscure tricks and alternate instructions like secret spells, while one commenter zooms all the way out to compare it to why life uses left‑handed amino acids and even diet soda chemistry. What started as “why do we use this instruction” turns into philosophy, biology, memes, and programmers proudly recognizing their friends’ code just by how they write zero. Drama level: petty, but cosmic.
Key Points
- •x86 compilers favor “xor r, r” to zero registers because it is more compact than “mov r, 0.”
- •“sub r, r” is equally compact and similar in cycles, but differs in flags: xor leaves AF undefined; sub clears AF.
- •The author proposes historical momentum and compiler output as reasons “xor r, r” became dominant.
- •Intel microarchitectures special-case both “xor r, r” and “sub r, r,” renaming to an internal zero register and breaking dependencies.
- •On Itanium, xor doesn’t clear the NaT bit, but the architecture offers a dedicated zero register for zeroing.