Last active
August 4, 2019 16:15
-
-
Save Silva97/6568b7ac88c8884b3b8557d925120154 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> | |
#include <inttypes.h> | |
uint32_t fib(int n) | |
{ | |
register uint32_t r = 0; | |
__asm__( | |
"mov $1, %%ebx\n\t" | |
".lp%=:\n\t" | |
" xaddl %%ebx, %0\n\t" | |
" sub $1, %1\n\t" | |
" testl %1, %1\n\t" | |
" jnz .lp%=" | |
: "+r" (r), | |
"+r" (n) | |
); | |
return r; | |
} | |
int main(void) | |
{ | |
int x; | |
scanf("%d", &x); | |
printf("fib(%d) = %" PRIu32 "\n", x, fib(x)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment