With thanks to Manos helping me to understand the Nasm style inline assembly, here is a quick example to calculate the size of a function :
#include <stdio.h>
int testfunc(int x,int y,int *pSize)
{
int result;
int temp;
asm
{
mov edx,label1
dec edx
l1:
inc edx
// Search for the RET ( 0xC3 ) instruction
cmp byte [edx], 0xC3
jne l1
mov dword [temp],edx
}
result=x;
result+=y;
*pSize=1+(int)temp-(int)testfunc;
label1:
return result;
}
int main(void)
{
int fSize;
testfunc(10,20,&fSize);
printf("Size of the function testfunc = %d bytes\n",fSize);
return 0;
}