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

问题描述

xor eax, eax总是将eax设置为零,对吗?那么,为什么有时MSVC ++会将其放入可执行文件的代码中? 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,因此执行时间是相同的./p>

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 

Also, what does it mean to do in al, dx?

解决方案

Yes, it is more efficient.

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.

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

10-22 09:06