寄存器与自身异或的目的是什么? [英] What is the purpose of XORing a register with itself?

查看:30
本文介绍了寄存器与自身异或的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

xor eax, eax 总是将 eax 设置为零,对吗?那么,为什么 MSVC++ 有时会将它放在我的可执行文件的代码中?mov eax, 0 是不是更高效?

xor eax, eax will always set eax to zero, right? So, why does MSVC++ sometimes put it in my executable's code? Is it more efficient that mov eax, 0?

012B1002  in          al,dx 
012B1003  push        ecx  
    int i = 5;
012B1004  mov         dword ptr [i],5 
    return 0;
012B100B  xor         eax,eax 

另外,in al, dx 是什么意思?

推荐答案

是的,效率更高.

操作码比mov eax, 0短,只有2个字节,处理器识别出这种特殊情况,把它当作一个mov eax, 0而没有假读取依赖于eax,所以执行时间是一样的.

The opcode is shorter than mov eax, 0, only 2 bytes, and the processor recognizes the special case and treats it as a mov eax, 0 without a false read dependency on eax, so the execution time is the same.

这篇关于寄存器与自身异或的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆