Is this how a recursive would work? I think I am missing something. I think I need two registers, but I don't know how to make it work. Here is what I have
;N is in eax
math:
push eax ;save callers ebx
cmp eax,1 ;compare eax to 1
ja non_base ;if above 1 jump to non_base
base:
mov eax,1 ;move 1 into eax
pop ebx ;return callers ebx
ret
non_base:
push eax ;save callers eax
sub eax,1 ;subtract 1 from eax
call math ;call math
ret
doesnt fibonacci go up? 1 1 2 3 5 8 11 and so on?, so why the dec eax?
well it is f(n)=(n-1)+(n-2) or that is the equation I am suppose to work with.
Better look again at the Fibonacci equation.
It's
F(n) = F(n-1) + F(n-2)
n, n-1, and n-2 aren't used in the equations as values. They are counters that indicate where in the sequence a specific Fibonacci number appears.
It's
F(n) = F(n-1) + F(n-2)
n, n-1, and n-2 aren't used in the equations as values. They are counters that indicate where in the sequence a specific Fibonacci number appears.
Ok, then I am completely confused...I have read over it a number of times, I just don't understand.
mov ecx, 10 ; loop count
mov eax, 1 ; first value
mov ebx, 1 ; second value
loopie:
; print value in eax, its the number (i didn't put this code in as i'm sure you can do it yourself for your homework)
lea edx, ; number = first + second
mov eax, ebx
mov ebx, edx
loop loopie
that code generates the sequence...
1 1 2 3 5 8 13 21 34 55 89 144
it can do more by adjusting ecx to a higher value
fibonacci sequence works by adding first and second to make new value, and working from that...
1 1 is the initial starting value...
1+1 = 2
1+2 = 3
2+3 = 5
3+5 = 8
and so on..