Tja... här är de två versionerna av den rekursiva funktionen.
void f()
{
004037F0 push ebp
004037F1 mov ebp,esp
004037F3 mov eax,1FBD4h
004037F8 call _chkstk (42CFF0h)
[1]
004037FD mov eax,dword ptr [___security_cookie (468EB8h)]
00403802 xor eax,dword ptr [ebp+4]
00403805 push edi
00403806 mov dword ptr [ebp-4],eax
//Utan denna variabel krashar aldrig funktionen
//när w och q är deklarerade inom if-statserna
char data[10000] = {0};
00403809 xor eax,eax
0040380B mov byte ptr [data],0
00403812 mov ecx,9C3h
00403817 lea edi,[ebp-0C353h]
0040381D rep stos dword ptr [edi]
0040381F stos word ptr [edi]
00403821 stos byte ptr [edi]
double w[10000] = {5};
00403822 xor eax,eax
00403824 mov ecx,4E1Eh
00403829 lea edi,[ebp-1FBCCh]
0040382F mov dword ptr [w],0
00403839 mov dword ptr [ebp-1FBD0h],40140000h
00403843 rep stos dword ptr [edi]
int q[10000] = {5};
00403845 mov ecx,270Fh
0040384A lea edi,[ebp-9C40h]
00403850 mov dword ptr [q],5
0040385A rep stos dword ptr [edi]
if (b)
0040385C mov al,byte ptr [b (46A2A0h)]
00403861 test al,al
00403863 pop edi
00403864 je f+87h (403877h)
{
//int q[10000] = {5};
std::cout << &q;
00403866 lea eax,[q]
0040386C push eax
0040386D mov ecx,offset std::cout (46A3ACh)
00403872 call std::basic_ostream<char,std::char_traits<char> >::operator<< (401041h)
}
if (a)
00403877 mov al,byte ptr [a (46A2A1h)]
0040387C test al,al
0040387E je f+0A1h (403891h)
{
//double w[10000] = {5};
std::cout << &w;
00403880 lea ecx,[w]
00403886 push ecx
00403887 mov ecx,offset std::cout (46A3ACh)
0040388C call std::basic_ostream<char,std::char_traits<char> >::operator<< (401041h)
}
count++;
00403891 mov eax,dword ptr [count (46A2A4h)]
std::cout << "Anrop nummer " << count << data << std::endl;
00403896 push offset std::endl (4010D2h)
0040389B lea edx,[data]
004038A1 push edx
004038A2 inc eax
004038A3 push eax
004038A4 push offset ___xt_z+104h (468030h)
004038A9 push offset std::cout (46A3ACh)
004038AE mov dword ptr [count (46A2A4h)],eax
004038B3 call std::operator<< (4013D9h)
004038B8 add esp,8
004038BB mov ecx,eax
004038BD call std::basic_ostream<char,std::char_traits<char> >::operator<< (401122h)
004038C2 push eax
004038C3 call std::operator<< (4013D9h)
004038C8 add esp,8
004038CB mov ecx,eax
004038CD call std::basic_ostream<char,std::char_traits<char> >::operator<< (4012B2h)
//Rekursiv funktion
f();
004038D2 call f (401258h)
}[/1]
void f()
{
004037F0 push ebp
004037F1 mov ebp,esp
004037F3 mov eax,15F94h
004037F8 call _chkstk (42CFF0h)
[1]
004037FD mov eax,dword ptr [___security_cookie (468EB8h)]
00403802 xor eax,dword ptr [ebp+4]
00403805 push edi
00403806 mov dword ptr [ebp-4],eax
//Utan denna variabel krashar aldrig funktionen
//när w och q är deklarerade inom if-statserna
char data[10000] = {0};
00403809 xor eax,eax
0040380B mov byte ptr [data],0
00403812 mov ecx,9C3h
00403817 lea edi,[ebp-2713h]
0040381D rep stos dword ptr [edi]
0040381F stos word ptr [edi]
00403821 stos byte ptr [edi]
//double w[10000] = {5};
//int q[10000] = {5};
if (b)
00403822 mov al,byte ptr [b (46A2A0h)]
00403827 test al,al
00403829 je f+65h (403855h)
{
int q[10000] = {5};
0040382B xor eax,eax
0040382D mov dword ptr [q],5
00403837 mov ecx,270Fh
0040383C lea edi,[ebp-0C350h]
00403842 rep stos dword ptr [edi]
std::cout << &q;
00403844 lea eax,[q]
0040384A push eax
0040384B mov ecx,offset std::cout (46A3ACh)
00403850 call std::basic_ostream<char,std::char_traits<char> >::operator<< (401041h)
}
if (a)
00403855 mov al,byte ptr [a (46A2A1h)]
0040385A test al,al
0040385C je f+0A2h (403892h)
{
double w[10000] = {5};
0040385E xor eax,eax
00403860 mov dword ptr [w],0
0040386A mov dword ptr [ebp-15F90h],40140000h
00403874 mov ecx,4E1Eh
00403879 lea edi,[ebp-15F8Ch]
0040387F rep stos dword ptr [edi]
std::cout << &w;
00403881 lea ecx,[w]
00403887 push ecx
00403888 mov ecx,offset std::cout (46A3ACh)
0040388D call std::basic_ostream<char,std::char_traits<char> >::operator<< (401041h)
}
count++;
00403892 mov eax,dword ptr [count (46A2A4h)]
std::cout << "Anrop nummer " << count << data << std::endl;
00403897 push offset std::endl (4010D2h)
0040389C lea edx,[data]
004038A2 push edx
004038A3 inc eax
004038A4 push eax
004038A5 push offset ___xt_z+104h (468030h)
004038AA push offset std::cout (46A3ACh)
004038AF mov dword ptr [count (46A2A4h)],eax
004038B4 call std::operator<< (4013D9h)
004038B9 add esp,8
004038BC mov ecx,eax
004038BE call std::basic_ostream<char,std::char_traits<char> >::operator<< (401122h)
004038C3 push eax
004038C4 call std::operator<< (4013D9h)
004038C9 add esp,8
004038CC mov ecx,eax
004038CE call std::basic_ostream<char,std::char_traits<char> >::operator<< (4012B2h)
//Rekursiv funktion
f();
004038D3 call f (401258h)
}[/1]
Följande stycke är hämtat från MSVC++:
chkstk.asm skrev:
;Entry:
; EAX = size of local frame
;
;Exit:
; ESP = new stackframe, if successful
;
;Uses:
; EAX
Exemplet med varaiblern inom if-satserna använde således 0x15F94 bytes minne, medan koden där alla variablerna deklarerades i början av funktionen använde 0x1FBD4 bytes.
Skillnaden blir exakt 40000 bytes i decimal form, det vill säga exakt det utrymme som de tiotusen integer tar upp. Dessa integers lagrades nämligen i (delvis) samma utrymme som flyttalen
