Skip to content

Instantly share code, notes, and snippets.

@Silva97
Last active August 4, 2019 16:15
Show Gist options
  • Save Silva97/6568b7ac88c8884b3b8557d925120154 to your computer and use it in GitHub Desktop.
Save Silva97/6568b7ac88c8884b3b8557d925120154 to your computer and use it in GitHub Desktop.
#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