美文网首页
函数的工作原理

函数的工作原理

作者: Justin_901e | 来源:发表于2019-07-17 18:29 被阅读0次

函数调用 约定:_cdecl, _stdcall, _fastcall

6 void _stdcall ShowStd(int nNumber) {

7 printf("Justin %d \r\n", nNumber);

8 }

9 void _cdecl ShowCde(int nNumber) {

10 printf("%d \r\n", nNumber);

11 }

12 void _fastcall ShowFast(int oOne, int oTwo, int nThree, int nFour) {

13 printf("%d %d %d %d \r\n", oOne, oTwo, nThree, nFour);

14 }

16 struct tagTEST

17 {

18 int m_nOne;

19 int m_nTwo;

20 };

21 tagTEST RetStruct() {

22 tagTEST testRet;

23 testRet.m_nOne = 1;

mov dword ptr ss:[ebp-C],1

24 testRet.m_nTwo = 2;

mov dword ptr ss:[ebp-8],2

26 return testRet;

mov eax,dword ptr ss:[ebp-C]  取结构体成员传入eax

mov edx,dword ptr ss:[ebp-8]  取结构体成员传入edx

27 }

29 int main()

30 {

31 ShowStd(5);

push 5

call function.3310B4

32 ShowCde(5);

push 5

call function.331136

add esp,4

33 ShowFast(1,2,3,4);

push 4

push 3

mov edx,2

mov ecx,1

call function.33109B

35 tagTEST test;

36 test = RetStruct();

call function.33101E  调用  RetStruct函数

mov dword ptr ss:[ebp-DC],eax  取  m_nOne 变量

mov dword ptr ss:[ebp-D8],edx 取  m_nTwo变量

经过几次数据传递,最终将返回结果存入结构体实例的两个成员所在地址处

mov eax,dword ptr ss:[ebp-DC]

mov dword ptr ss:[ebp-C],eax    

mov ecx,dword ptr ss:[ebp-D8]

mov dword ptr ss:[ebp-8],ecx

38     return 0;

39}

相关文章

网友评论

      本文标题:函数的工作原理

      本文链接:https://www.haomeiwen.com/subject/dyuclctx.html