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
            push        eax                ;save callers ebx
            cmp        eax,1              ;compare eax to 1
            ja          non_base            ;if above 1 jump to non_base
            mov        eax,1              ;move 1 into eax
            pop        ebx                ;return callers ebx
            push        eax                ;save callers eax
            sub        eax,1              ;subtract 1 from eax
            call        math                ;call math
Posted on 2008-07-13 15:30:49 by cannsyl
doesnt fibonacci go up? 1 1 2 3 5 8 11 and so on?, so why the dec eax?
Posted on 2008-07-14 00:37:32 by evlncrn8
well it is f(n)=(n-1)+(n-2) or that is the equation I am suppose to work with.
Posted on 2008-07-14 14:26:49 by cannsyl
Better look again at the Fibonacci equation.


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.
Posted on 2008-07-14 19:00:00 by tenkey
Ok, then I am completely confused...I have read over it a number of times, I just don't understand.
Posted on 2008-07-14 20:01:12 by cannsyl
mov ecx, 10    ; loop count
mov eax, 1      ; first value
mov ebx, 1      ; second value


; 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..
Posted on 2008-07-15 02:14:53 by evlncrn8