First on the code:
Naked.cpp:
#include "stdafx.h"
extern "C" int __declspec (naked) add2 (int x,int y)//reference description supports cross-file invocation
{
__asm{//function environment initialization (stack, protect field, fill buffer)
PUSH EBP
MOV Ebp,esp
SUB esp,0x40
PUSH EBX
PUSH ESI
PUSH EDI
LEA Edi,dword PTR ss:[ebp-0x40]
MOV EAX,0XCCCCCCCC
MOV ecx,0x10
REP Stosd
}
__asm{//Function function
MOV Eax,dword PTR ss:[ebp+0x8]
ADD Eax,dword PTR ss:[ebp+0xc]
}
__asm{//Restore existing descending stack return
POP EDI
POP ESI
POP EBX
MOV ESP,EBP
POP EBP
Ret
}
}
====================================================
Base.cpp
#include "stdafx.h"
extern "C" int add2 (int,int); declaring external functions
int _tmain (int argc, _tchar* argv[])
{
Test
int sum=0;
printf ("Add2 (50,76):%d\n", Add2 (50,76));
return 0;
}
Today deepens understanding of a C language function of the operating mechanism.
First contact with C language bare function