Task: Fibonacci
You will solve this exercise starting from the fibonacci.asm
file located in the tasks/fibonacci
directory.
Calculate the Nth Fibonacci number, where N is given through the eax
register.
NOTE: The Nth Fibonacci number is
F[N]
for our chosen N. By definition,F[0] = 0
andF[1] = F[2] = 1
. Each following value is calculated with the formulaF[i] = F[i - 1] + F[i - 2]
.TIP: For example, if the value stored in
ecx
is equal to5
, a correct solution will display5
and for7
, it will display13
.
To test the implementation, enter the tests/
directory and run:
make check
In case of a correct solution, you will get an output such as:
./run_all_tests.sh
test_fibonacci ........................ passed ... 100
========================================================================
Total: 100/100
NOTE : If you wish to test for various values of N, just change its value at line
6
insupport/fibonacci.asm
to whatever you desire (that whatever should fit in 4 bytes, of course :-) ).
If you’re having difficulties solving this exercise, go through this reading material.