我剛剛注意到一些奇怪的空主函數的彙編語言代碼。用Visual C++編譯器解釋空C`main`函數的奇怪程序集
//filename: main.c
void main()
{
}
拆解:
push ebp
mov ebp,esp
sub esp,0C0h; why on the earth is it reserving 192 bytes?
push ebx
push esi
push edi ; good compiler. Its saving ebx, esi & edi values.
lea edi,[ebp-0C0h] ; line 1
mov ecx,30h ; line 2
mov eax,0CCCCCCCCh ; line 3
rep stos dword ptr es:[edi] ; line 4
xor eax,eax ; returning value 0. Code following this line is explanatory.
pop edi ; restoring the original states of edi,esi & ebx
pop esi
pop ebx
mov esp,ebp
pop ebp
ret
- 爲什麼地球上它保留了功能192個字節,其中沒有任何變量
- 怎麼了四大行:1號線, 2,第3行,第4行?它試圖做什麼&爲什麼?
爲什麼不突出顯示代碼語法? – claws 2010-07-29 13:25:05
裝配非空主語句時產生了什麼程序集,以及將main的返回類型更改爲int時會發生什麼? – 2010-07-29 13:29:17
值得指出的是主要回報int。使用void作爲main不是很好。 – nmichaels 2010-07-29 13:30:21