

After a very painful process I programmed a function to calculate the n
th 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(n1) + fib(n2)
 Using the stack to store
n
andn1
in the stack frames of each procedure