Thread: strange 4 assembly instructions for a function

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    strange 4 assembly instructions for a function

    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;
    }

    thanks in advance,
    George

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Those 4 instructions fill 192 bytes of stackspace [allocated by the sub esp, C0h]. It does this to detect stack overflows. As far as I know, this only happens in debug builds.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Brand new to C need favor
    By dontknowc in forum C Programming
    Replies: 5
    Last Post: 09-21-2007, 10:08 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM