📰 2026-04-22 15:30 更新
🔸 XOR’ing a register with itself is the idiom for zeroing it out. Why not sub? / 异或寄存器本身是将其归零的习惯用法。为什么不选择SUB ?
🔗 XOR’ing a register with itself is the idiom for zeroing it out. Why not sub?
🔥 10 points
原文:
Matt Godbolt, probably best known for being the proprietor of Compiler Explorer, wrote a brief article on why x86 compilers love the xor eax, eax instruction. The answer is that it is the most compact way to set a register to zero on x86. In particular, it is several bytes shorter than the more obvious mov eax, 0 since it avoids having to encode the four-byte constant. The x86 architecture does not have a dedicated zero register, so if you need to zero out a register, you’ll have to do it ab…
译文:
Matt Godbolt可能以编译器资源管理器的所有者而闻名,他写了一篇简短的文章,解释了为什么x86编译器喜欢XOR EAX、EAX指令。答案是,这是在x86上将寄存器设置为零的最紧凑的方法。特别是,它比更明显的mov eax短几个字节, 0 ,因为它避免了对四字节常量进行编码。x86架构没有专用的零寄存器,因此如果您需要 要清零一个寄存器,你必须这样做……
自动更新 · 正文抓取 · 双语翻译