任何理由做" XOR EAX,EAX"? [英] Any reason to do a "xor eax, eax"?

查看:150
本文介绍了任何理由做" XOR EAX,EAX"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XOR EAX,EAX 总是设置 EAX 为零,对不对?那么,为什么MSVC ++有时把它放在我的可执行文件的code?它是更为有效的做法 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 

此外,这是什么意思办在人,DX

推荐答案

是的,这是更有效的。

运算code比 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.

这篇关于任何理由做" XOR EAX,EAX"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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