| |
After a very painful process I programmed a function to calculate the nth Fibonacci number with assembly. For this solution, I used the Intel syntax on an x86 architecture.
I found that doing this recursive problem required understanding how to organize your control and data transfers across function calls. This included understanding the stack as a data structure, the stack pointer (rsp register), and the program counter (rip register).
The key details to getting the solution right included:
- Handling the base case
- Having both fibonacci calls in the general case to calculate
fib(n-1) + fib(n-2) - Using the stack to store
nandn-1in the stack frames of each procedure