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
31follows theXOR r/m32, r32format: This means the first operand (r/m32) is the destination, and the second (r32) is the source. Forxor eax, eax, the ModRM byte paired with31is0xC0(since both the destination r/m and source register areeax, which is register ID 0). The full machine code here is31 C0. - Opcode
33follows theXOR r32, r/m32format: Here, the first operand (r32) is the destination, and the second (r/m32) is the source. Forxor eax, eax, the ModRM byte is also0xC0(again, both operands areeax), making the full machine code33 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
eaxregister (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(destinationebx, sourceeax), you'd use31 C3(opcode31+ ModRM byte0xC3). - If you wanted
xor eax, ebx(destinationeax, sourceebx), you'd use33 D8(opcode33+ ModRM byte0xD8).
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
相关产品推荐
相关产品推荐

