Hello everyone,


I am confused what is the function of the 4 assembly instructions? I posted
the 4 assembly instructions and related whole source code/assembly code below.

Any ideas?

[Code]
00BA13CC lea edi,[ebp-0C0h]
00BA13D2 mov ecx,30h
00BA13D7 mov eax,0CCCCCCCCh
00BA13DC rep stos dword ptr es:[edi]


int sumExample (int a, int b)
{
00BA13C0 push ebp
00BA13C1 mov ebp,esp
00BA13C3 sub esp,0C0h
00BA13C9 push ebx
00BA13CA push esi
00BA13CB push edi
00BA13CC lea edi,[ebp-0C0h]
00BA13D2 mov ecx,30h
00BA13D7 mov eax,0CCCCCCCCh
00BA13DC rep stos dword ptr es:[edi]
return a + b;
00BA13DE mov eax,dword ptr [a]
00BA13E1 add eax,dword ptr [b]
}

#include <iostream>

using namespace std;

int sumExample (int a, int b)
{
return a + b;
}

int main()
{
int c = sumExample (100, 200);

cout << c << endl;

return 0;
}

[/Code]


thanks in advance,
George

Re: strange 4 assembly instructions for a function by Alf

Alf
Mon Jul 21 04:15:26 CDT 2008

* George:
> Hello everyone,
>
>
> I am confused what is the function of the 4 assembly instructions? I posted
> the 4 assembly instructions and related whole source code/assembly code below.
>
> Any ideas?
>
> [Code]
> 00BA13CC lea edi,[ebp-0C0h]
> 00BA13D2 mov ecx,30h
> 00BA13D7 mov eax,0CCCCCCCCh
> 00BA13DC rep stos dword ptr es:[edi]

It stores some 48 dwords downwards in the stack. Perhaps this is code that
checks for stack overflow. Or perhaps it's meant to help to later check for
stack corruption (e.g., returning to address 0CCCCCCCCh would indicate stack
pointer corruption).

Anyway, you can probably just ignore this code.

Most likely it's not present in release build (disclaimer: haven't checked).


Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Re: strange 4 assembly instructions for a function by Norbert

Norbert
Mon Jul 21 08:18:58 CDT 2008

George schrieb:
> Hello everyone,
>
>
> I am confused what is the function of the 4 assembly instructions? I posted
> the 4 assembly instructions and related whole source code/assembly code below.
>
> Any ideas?
>
> [Code]
> 00BA13CC lea edi,[ebp-0C0h]
> 00BA13D2 mov ecx,30h
> 00BA13D7 mov eax,0CCCCCCCCh
> 00BA13DC rep stos dword ptr es:[edi]

It is a result of the runtime error checks that are active in the debug
version of your programm. See the documentation of the /RTC compiler
option for more information:

http://msdn.microsoft.com/en-us/library/8wtf2dfz(VS.80).aspx

Norbert