Fight_ 发表于 2016-3-30 09:41:45

谁可以帮个忙,把用c写的函数翻译成汇编

如题,函数为:Int Sum(int a,int b){
                                int c;
                                c=a+b;
                                return c;
                        }
多谢了 我就想学习一下

yundi 发表于 2016-4-23 13:24:45

看书刚学到的方法,用VS写一个c程序,然后编译,逐句调试,再点鼠标右键,选“转到反汇编”,就可以看到汇编的代码了。
int Sum(int a,int b)
{
00991420push      ebp
00991421mov         ebp,esp
00991423sub         esp,0CCh
00991429push      ebx
0099142Apush      esi
0099142Bpush      edi
0099142Clea         edi,
00991432mov         ecx,33h
00991437mov         eax,0CCCCCCCCh
0099143Crep stos    dword ptr es:
        int c;
        c=a+b;
0099143Emov         eax,dword ptr
00991441add         eax,dword ptr
00991444mov         dword ptr ,eax
        return c;
00991447mov         eax,dword ptr
}
0099144Apop         edi
0099144Bpop         esi
0099144Cpop         ebx
0099144Dmov         esp,ebp
0099144Fpop         ebp
00991450ret

int main()
{
009913A0push      ebp
009913A1mov         ebp,esp
009913A3sub         esp,0CCh
009913A9push      ebx
009913AApush      esi
009913ABpush      edi
009913AClea         edi,
009913B2mov         ecx,33h
009913B7mov         eax,0CCCCCCCCh
009913BCrep stos    dword ptr es:
        int x;
        x = Sum(3,2);
009913BEpush      2
009913C0push      3
009913C2call      @ILT+270(_Sum) (991113h)
009913C7add         esp,8
009913CAmov         dword ptr ,eax
        printf("%d",x);
009913CDmov         esi,esp
009913CFmov         eax,dword ptr
009913D2push      eax
009913D3push      offset string "%d" (99573Ch)
009913D8call      dword ptr
009913DEadd         esp,8
009913E1cmp         esi,esp
009913E3call      @ILT+310(__RTC_CheckEsp) (99113Bh)
        getch();
009913E8call      @ILT+130(__getch) (991087h)
}
009913EDxor         eax,eax
009913EFpop         edi
009913F0pop         esi
009913F1pop         ebx
009913F2add         esp,0CCh
009913F8cmp         ebp,esp
009913FAcall      @ILT+310(__RTC_CheckEsp) (99113Bh)
009913FFmov         esp,ebp
00991401pop         ebp
00991402ret

dt3tc 发表于 2016-4-24 18:18:34

像这样写
gcc 1.c -S 1.s
就行了
页: [1]
查看完整版本: 谁可以帮个忙,把用c写的函数翻译成汇编