user-0 提问: 如何使用内嵌汇编实现斐波那契数列，求出第N个数

回复:
user: user-1
content: 参考下面： 15:       if (n<2) { 0040104E   cmp         dword ptr [ebp-4],2 00401052   jge         main+68h (00401078) 16:           r=n; 00401054   mov         ecx,dword ptr [ebp-4] 00401057   mov         dword ptr [ebp-8],ecx 17:           printf("fib(%d) = %d\n", n, r); 0040105A   mov         edx,dword ptr [ebp-8] 0040105D   push        edx 0040105E   mov         eax,dword ptr [ebp-4] 00401061   push        eax 00401062   push        offset string "fib(%d) = %d\n" (00413020) 00401067   call        dword ptr [__imp__printf (004150b0)] 0040106D   add         esp,0Ch 18:           return r; 00401070   mov         eax,dword ptr [ebp-8] 00401073   jmp         main+101h (00401111) 19:       } else { 20:           char *argv2[2]; 21:           char argv21[3]; 22:           argv2[1]=argv21; 00401078   lea         ecx,[argv21] 0040107B   mov         dword ptr [ebp-0Ch],ecx 23:           sprintf(argv2[1],"%d",n-2); 0040107E   mov         edx,dword ptr [ebp-4] 00401081   sub         edx,2 00401084   push        edx 00401085   push        offset string "%d" (0041301c) 0040108A   mov         eax,dword ptr [ebp-0Ch] 0040108D   push        eax 0040108E   call        dword ptr [__imp__sprintf (004150a8)] 00401094   add         esp,0Ch 24:           r=main(2,argv2); 00401097   lea         ecx,[argv2] 0040109A   push        ecx 0040109B   push        2 0040109D   call        @ILT+0(_main) (00401005) 004010A2   add         esp,8 004010A5   mov         dword ptr [ebp-8],eax 25: 26:           char *argv1[2]; 27:           char argv11[3]; 28:           argv1[1]=argv11; 004010A8   lea         edx,[argv11] 004010AB   mov         dword ptr [ebp-18h],edx 29:           sprintf(argv1[1],"%d",n-1); 004010AE   mov         eax,dword ptr [ebp-4] 004010B1   sub         eax,1 004010B4   push        eax 004010B5   push        offset string "%d" (0041301c) 004010BA   mov         ecx,dword ptr [ebp-18h] 004010BD   push        ecx 004010BE   call        dword ptr [__imp__sprintf (004150a8)] 004010C4   add         esp,0Ch 30:           r+=main(2,argv1); 004010C7   lea         edx,[argv1] 004010CA   push        edx 004010CB   push        2 004010CD   call        @ILT+0(_main) (00401005) 004010D2   add         esp,8 004010D5   mov         ecx,dword ptr [ebp-8] 004010D8   add         ecx,eax 004010DA   mov         dword ptr [ebp-8],ecx 31:           printf("fib(%d) = %d\n", n, r); 004010DD   mov         edx,dword ptr [ebp-8] 004010E0   push        edx 004010E1   mov         eax,dword ptr [ebp-4] 004010E4   push        eax 004010E5   push        offset string "fib(%d) = %d\n" (00413020) 004010EA   call        dword ptr [__imp__printf (004150b0)] 004010F0   add         esp,0Ch 32:           return r; 004010F3   mov         eax,dword ptr [ebp-8] 004010F6   jmp         main+101h (00401111) 33:       } 34: 35:       __asm { 36: 37:       // FILL YOUR CODE HERE 38:       // evaluate r = f(n) 39:           nop 004010F8   nop 40:       }

user: user-1
content: 将以下C代码对应汇编指令手动翻译为嵌入汇编语法代替nop指令： //斐波那契数列：0,1,1,2,3,5,8,13,21.。。。 //f(n)=f(n-2)+f(n-1) //f(0)=0 //f(1)=1 #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) {     int n, r;     if (argc < 2) {         printf("Usage: %s number(<40)\n", argv[0]);         return -1;     }     n = atoi(argv[1]);      if (n<2) {         r=n;         printf("fib(%d) = %d\n", n, r);         return r;     } else {         char *argv2[2];         char argv21[3];         argv2[1]=argv21;         sprintf(argv2[1],"%d",n-2);         r=main(2,argv2);          char *argv1[2];         char argv11[3];         argv1[1]=argv11;         sprintf(argv1[1],"%d",n-1);         r+=main(2,argv1);         printf("fib(%d) = %d\n", n, r);         return r;     }      __asm {      // FILL YOUR CODE HERE     // evaluate r = f(n)         nop     }     printf("fib(%d) = %d\n", n, r);     return 0; }

user: user-2
content: 为什么要使用汇编, 是为了学习汇编还是为了速度