-
-
Save gabrielsaints/577f194921931760239d2b2929e38ff6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/** | |
* Sequência de Fibonacci otimizada com Inline Assembly | |
*/ | |
int fib(int n) | |
{ | |
register int r = 0; | |
__asm__( | |
"movl %1, %%ecx\n\t" | |
"movl $1, %%ebx\n\t" | |
".lp:\n\t" | |
" xaddl %%ebx, %0\n\t" | |
" loop .lp" | |
: "+r" (r) | |
: "r" (n) | |
); | |
return r; | |
} | |
int main(void) | |
{ | |
int x; | |
scanf("%d", &x); | |
printf("fib(%d) = %d\n", x, fib(x)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment