You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

x86架构中XOR eax,eax对应31与33 opcode的差异疑问

Do 31 and 33 Opcodes Differ for xor eax, eax?

Great question—let's unpack this clearly. When working with the specific instruction xor eax, eax, both opcodes (31 and 33) will functionally do exactly the same thing, but there are subtle encoding differences under the hood. Here's the breakdown:

Key Differences in Encoding

The two opcodes correspond to different operand order formats:

  • Opcode 31 follows the XOR r/m32, r32 format: This means the first operand (r/m32) is the destination, and the second (r32) is the source. For xor eax, eax, the ModRM byte paired with 31 is 0xC0 (since both the destination r/m and source register are eax, which is register ID 0). The full machine code here is 31 C0.
  • Opcode 33 follows the XOR r32, r/m32 format: Here, the first operand (r32) is the destination, and the second (r/m32) is the source. For xor eax, eax, the ModRM byte is also 0xC0 (again, both operands are eax), making the full machine code 33 C0.

Functional Equivalence for xor eax, eax

Even though the machine codes are different, executing either will produce identical results:

  • Both will zero out the eax register (since XORing a value with itself always yields 0).
  • All flag updates (zero flag set, parity flag based on the 0 result, etc.) are identical.
  • There's no measurable performance difference between the two on modern x86 CPUs—they're treated as equivalent in execution pipelines.

Why Two Opcodes Exist

These opcodes exist to support flexible operand ordering for more complex instructions. For example:

  • If you wanted xor ebx, eax (destination ebx, source eax), you'd use 31 C3 (opcode 31 + ModRM byte 0xC3).
  • If you wanted xor eax, ebx (destination eax, source ebx), you'd use 33 D8 (opcode 33 + ModRM byte 0xD8).

In short: For xor eax, eax, the only difference is the machine code bytes—there's no functional or behavioral difference when executed.

内容的提问来源于stack exchange,提问作者Maverick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:42:42