I am trying to write a version of the Fibonacci assembly code that gives the nth Fibonacci number and returns it.
For some reason, he has problems with saving the return value of Fibonacci numbers and adding them.
I want him to print the nth Fibonacci number.
I made some changes to my code, now it is still incorrect, but it is closer. Now he tells me that the 11th fibonacci number is 48. Still not true, but do we get somewhere to the right?
.text .globl _fibonacci _fibonacci: pushl %ebp movl %esp,%ebp push %esi movl 8(%ebp),%esi cmp $1,%esi jle BASE sub $1,%esi push %esi call _fibonacci add $4,%esp movl %eax,%edx sub $1,%esi push %esi call _fibonacci add $4,%esp add %eax,%edx movl %edx,%eax DONE: pop %esi pop %ebp ret BASE: mov $1,%eax jmp DONE
I call this assembly code using C:
#include <stdio.h> int fibonacci(int n); int main(void){ int n=111; int x=fibonacci(n); printf("The %d fibonaacci number is %d\n",n,x); }
source share