有人可以告诉我这两个的目的是什么吗push ecx
下面的说明?我不明白他们到底要做什么?
我意识到push epb
正在保存堆栈基指针,然后mov epb, esp
正在将堆栈指针分配给前一个堆栈基指针。
int main(){
01301190 push ebp
01301191 mov ebp,esp
01301193 push ecx ;here??
01301194 mov dword ptr [h],0CCCCCCCCh
int h = my_func(1,3);
int my_func(int a, int b){
01301160 push ebp
01301161 mov ebp,esp
01301163 push ecx ;here??
01301164 mov dword ptr [m],0CCCCCCCCh
int m = 0;
0130116B mov dword ptr [m],0
m = a*b;
01301172 mov eax,dword ptr [a]
01301175 imul eax,dword ptr [b]
01301179 mov dword ptr [m],eax
return m;
0130117C mov eax,dword ptr [m]
}
0130117F mov esp,ebp
}
01301181 pop ebp
01301182 ret
The push ecx
在堆栈上为局部变量分配 4 个字节(m
and h
)。实际内容为ecx
没关系 - 分配的槽会立即被覆盖0CCCCCCCCh
(Visual C++ 在调试版本中使用此神奇值来标记未初始化的变量)。
Visual C++经常使用push ecx
and pop ecx
作为替代品sub esp, 4
and add esp, 4
。为什么?有以下几个原因:
push ecx
and pop ecx
是单字节指令,而add
and sub
每个都是三个字节。差异可能不是很大,但所有函数中保存的所有字节加起来可能会很重要。
ecx
被认为被函数调用破坏了,所以可以安全地用pop ecx
函数调用后。所以你经常会看到这样的代码:
push arg1 ; push an argument
call __func1 ; call the function
pop ecx ; restore the stack
For push
,没有真正的理由使用ecx
具体来说 - 任何基本寄存器都可以。我想它只是为了对称而选择的,或者不要与非易失性寄存器的实际保存相混淆,例如esi
or edi
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)