I am not sure whether this is the right place to ask this question.
I would like to write a register machine code which when given an input of n in register 1, returns (also in register 1) the nth Fibonacci number. The Fibonacci numbers are 0 (the 0th), 1 (the 1st), 1 = 0 + 1 (the 2nd), etc.
I tried to write few lines of the codes, but unable to do the recursive property of Fibonacci sequence. Here is my code:
Let A, B, C be registers.
- (-A; 2,-)
- (+C; 1)
- (-C; 4,-)
- (+B; 5)
- (+A; 3)
I know that the fifth line is wrong but have no idea how to fix it. And I want to code to be as simple as possible (i.e. with fewest instructions). Thanks in advance.