c++代码: | c++代码: | c++代码: |
#include<iostream> | #include<iostream> | #include<iostream> |
using namespace std; | using namespace std; | using namespace std; |
int main() | int main() | int main() |
{ | { | { |
cout<<"输出"; | cout<<"输出"<<endl; | cout<<"输出"<<"Good"<<endl; |
return 0; | return 0; | return 0; |
} | } | } |
push offset sub_401030 | push offset sub_401040 | |
push offset aGood ; "Good" | ||
push offset aF ; "输? | push offset aF ; "输? | push offset aF ; "输? |
push offset unk_41A468 ; int | push offset unk_41A468 ; int | push offset unk_41A468 ; int |
call sub_401020 | call sub_402230 | call sub_402240 |
add esp, 8 | add esp, 8 | add esp, 8 |
push eax ; int | ||
call sub_402240 | ||
add esp, 8 | ||
mov ecx, eax | mov ecx, eax | |
call sub_401050 | call sub_401060 |
以下着重研究最后一段代码
push offset sub_401040 | 可以看出这个与<<endl;有关。 |
push offset aGood ; "Good" | push第二个输出内容,但是它没有和下面的参数一起被处理 ,而是在先输出”输出”之后的另一个call里才使用到了它。可见处理cout是先将所有参数都push了,然后再一个一个处理。 |
push offset aF ; "输? | 这三行是一个整体,即可以辨别sub_402240这个函数需要两个参数,而我一直对第一个参数不理解是什么作用。这个整体运行完就会出现”输出”而没有”Good”。 |
push offset unk_41A468 ; int | |
call sub_402240 | |
add esp, 8 | 这行是清理掉上个函数所用到的两个参数。同时使”Good”成为栈顶 |
push eax ; int | 这个和push offset unk_41A468 ;应该差不多,但是这个eax是怎么来的呢?我一直追踪下去,没有什么斩获,是我能力太低了的原因。但是可以猜测它的作用的。 |
call sub_402240 | |
add esp, 8 | 清理掉上个函数所用到的两个参数。使offset sub_401040成为栈顶 |
mov ecx, eax | 这步的用意是什么?可能是后一个call使用到了ecx这个参数。 |
call sub_401060 | 前面的一切疑惑要深入这个函数才能知晓,比如最先push的那个参数怎么没有使用和销毁呢? |
现在来看看sub_401060里面的代码
sub_401060 proc near | |
var_4= dword ptr -4 | 这是解释代码,即可理解为var_4是esp-4处的空间 |
arg_0= dword ptr 8 | 这是解释代码,即可理解为arg_0是esp+8处的空间 |
push ebp | |
mov ebp, esp | |
push ecx | |
mov [ebp+var_4], ecx | 这两句其实就是mov eax,ecx。至于为什么这么做就不清楚了?结合上面的代码mov ecx,eax。发现这就是一个循环, 只可以猜测这样的处理是因为之后call 的函数之中也有用到ecx(可能里面还是一个这个循环)。 |
mov eax, [ebp+var_4] | |
push eax | |
call [ebp+arg_0] | |
add esp, 4 | 这两句很奇怪啊,既然之后要给esp赋值,为什么之前还要有一次对它进行+操作?之前有两个push,则这步使esp编程这个子程没有被调用之前的值。即清理掉了前两个参数。 |
mov esp, ebp | |
pop ebp | |
retn 4 | 这句返回esp+4地址。即跳过了call操作push入的地址而跳到主体push offset sub_401040.压入的 sub_401040.。 |
反思: | 还有很多细节没有弄清楚 |
下步: | 增加cin |
973

被折叠的 条评论
为什么被折叠?



