飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 3006|回复: 4

[C/C++] 为想明白的函数指针

[复制链接]
  • TA的每日心情
    郁闷
    2017-1-19 11:18
  • 签到天数: 6 天

    [LV.2]偶尔看看I

    发表于 2011-1-21 19:03:29 | 显示全部楼层 |阅读模式
    int *max(int a,int b)
    {                 if(a>b) return &a;
             else return &b;        
    }
    void main()
    {        
    int * p = max(40,50);
    int * q = max(10,20);
      printf("%d \n",(*q) + (* p) );
    printf("%d \n",(*max(79,89))+(*max(10,40)));
    }
    PYG19周年生日快乐!
  • TA的每日心情
    郁闷
    2017-1-19 11:18
  • 签到天数: 6 天

    [LV.2]偶尔看看I

     楼主| 发表于 2011-1-22 11:53:10 | 显示全部楼层
    1. push ebp
    2. .text:00401091 mov ebp, esp
    3. .text:00401093 sub esp, 44h
    4. .text:00401096 push ebx
    5. .text:00401097 push esi
    6. .text:00401098 push edi
    7. .text:00401099 push 32h ; b
    8. .text:0040109B push 28h ; a
    9. .text:0040109D call j__max
    10. .text:004010A2 add esp, 8
    11. .text:004010A5 mov [ebp+p], eax
    12. .text:004010A8 push 46h ; b
    13. .text:004010AA push 3Ch ; a
    14. .text:004010AC call j__a1
    15. .text:004010B1 add esp, 8
    16. .text:004010B4 mov eax, [eax]
    17. .text:004010B6 mov ecx, [ebp+p]
    18. .text:004010B9 add eax, [ecx]
    19. .text:004010BB push eax
    20. .text:004010BC push offset format ; "%d \n"
    21. .text:004010C1 call _printf
    22. .text:004010C6 add esp, 8
    23. .text:004010C9 pop edi
    24. .text:004010CA pop esi
    25. .text:004010CB pop ebx
    26. .text:004010CC mov esp, ebp
    27. .text:004010CE pop ebp
    28. .text:004010CF retn
    29. .text:004010CF _main endp
    30. int *__cdecl j__a1(int a, int b)
    31. .text:0040100F j__a1 proc near ; CODE XREF: _main+1Cp
    32. .text:0040100F jmp _a1
    33. .text:0040100F j__a1 endp
    34. .text:0040100F
    35. .text:0040100F ; ---------------------------------------------------------------------------
    36. .text:00401014 db 1Ch dup(0CCh)
    37. .text:00401030
    38. .text:00401030 ; =============== S U B R O U T I N E =======================================
    39. .text:00401030
    40. .text:00401030 ; Attributes: bp-based frame
    41. .text:00401030
    42. .text:00401030 ; int *__cdecl max(int a, int b)
    43. .text:00401030 _max proc near ; CODE XREF: j__maxj
    44. .text:00401030
    45. .text:00401030 a = dword ptr 8
    46. .text:00401030 b = dword ptr 0Ch
    47. .text:00401030
    48. .text:00401030 push ebp
    49. .text:00401031 mov ebp, esp
    50. .text:00401033 sub esp, 40h
    51. .text:00401036 push ebx
    52. .text:00401037 push esi
    53. .text:00401038 push edi
    54. .text:00401039 mov eax, [ebp+a]
    55. .text:0040103C cmp eax, [ebp+b]
    56. .text:0040103F jle short loc_401046
    57. .text:00401041 lea eax, [ebp+a]
    58. .text:00401044 jmp short loc_401049
    59. .text:00401046 ; ---------------------------------------------------------------------------
    60. .text:00401046
    61. .text:00401046 loc_401046: ; CODE XREF: _max+Fj
    62. .text:00401046 lea eax, [ebp+b]
    63. .text:00401049
    64. .text:00401049 loc_401049: ; CODE XREF: _max+14j
    65. .text:00401049 pop edi
    66. .text:0040104A pop esi
    67. .text:0040104B pop ebx
    68. .text:0040104C mov esp, ebp
    69. .text:0040104E pop ebp
    70. .text:0040104F retn
    71. .text:0040104F _max endp
    72. .text:0040104F
    73. .text:0040104F ; ---------------------------------------------------------------------------
    74. .text:00401050 db 10h dup(0CCh)
    75. .text:00401060
    76. .text:00401060 ; =============== S U B R O U T I N E =======================================
    77. .text:00401060
    78. .text:00401060 ; Attributes: bp-based frame
    79. .text:00401060
    80. .text:00401060 ; int *__cdecl a1(int a, int b)
    81. .text:00401060 _a1 proc near ; CODE XREF: j__a1j
    82. .text:00401060
    83. .text:00401060 a = dword ptr 8
    84. .text:00401060 b = dword ptr 0Ch
    85. .text:00401060
    86. .text:00401060 push ebp
    87. .text:00401061 mov ebp, esp
    88. .text:00401063 sub esp, 40h
    89. .text:00401066 push ebx
    90. .text:00401067 push esi
    91. .text:00401068 push edi
    92. .text:00401069 mov eax, [ebp+a]
    93. .text:0040106C cmp eax, [ebp+b]
    94. .text:0040106F jle short loc_401076
    95. .text:00401071 lea eax, [ebp+a]
    96. .text:00401074 jmp short loc_401079
    97. .text:00401076 ; ---------------------------------------------------------------------------
    98. .text:00401076
    99. .text:00401076 loc_401076: ; CODE XREF: _a1+Fj
    100. .text:00401076 lea eax, [ebp+b]
    101. .text:00401079
    102. .text:00401079 loc_401079: ; CODE XREF: _a1+14j
    103. .text:00401079 pop edi
    104. .text:0040107A pop esi
    105. .text:0040107B pop ebx
    106. .text:0040107C mov esp, ebp
    107. .text:0040107E pop ebp
    108. .text:0040107F retn
    109. .text:0040107F _a1 endp
    复制代码
    PYG19周年生日快乐!
  • TA的每日心情
    郁闷
    2017-1-19 11:18
  • 签到天数: 6 天

    [LV.2]偶尔看看I

     楼主| 发表于 2011-1-25 02:38:01 | 显示全部楼层
    想明白了,结贴/:12
    PYG19周年生日快乐!
  • TA的每日心情
    郁闷
    2019-4-11 09:20
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2011-2-4 20:25:21 | 显示全部楼层
    看了有收获
    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2015-9-12 22:31
  • 签到天数: 1 天

    [LV.1]初来乍到

    发表于 2011-2-14 10:11:22 | 显示全部楼层
    /:L 给点中文……新手更明白……
    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表