First of all hi :),

I'm having problems with the fibonacci formula is ASM, it's easy in C:

``pow((1 + sqrt(5)) / 2, n) - pow((1 - sqrt(5)) / 2, n) / sqrt(5)``

Posted on 2005-08-15 23:45:36 by Lenin
the search button is your friend, use it, there are quite a few already existing threads on the fibonacci code in asm, one even in a macro if i remember correctly.
Posted on 2005-08-16 02:20:12 by evlncrn8
pow( (1 + sqrt(5) ) / 2, n) - pow( (1 - sqrt(5) ) / 2, n) / sqrt(5)

a=sqrt(5)
b=1
b=b+a
b=b/2
c=1
c=c-a
c=c/2
b=pow(b,n)
c=pow(c,n)
c=c/a
result=b-c

now you just have to write this in asm, either using
Raymond's fpulib or your own fpu code.
Posted on 2005-08-16 07:17:53 by drizz
Thanks you both, the main point of this thread was not only to get the fibonacci formula, but how to implement a formula in ASM, that's why I did post it.

I just searched and found the fibonacci ASM code, now let's go to google find out how to do pow and sqrt.

EDIT: I somehow screwed up while optimizing that fibonacci funtion, here's the working one

``(pow(1 + sqrt(5), n) - pow(1 - sqrt(5), n)) / (sqrt(5) * pow(2, n))``
Posted on 2005-08-16 16:38:02 by Lenin
I tried changing  Alone's code to fit my purposes but my code dosen't work...

``                invoke GetDlgItemInt, hWnd, IDC_EDIT1, NULL, FALSE               	mov num, eax               	               	mov eax, 1                 	mov ebx, 0 ; Set initial values               	mov ecx, 0               	               	here:               	 add ecx, eax               	 mov eax, ebx  ; Copy ebx into eax               	 mov ebx, ecx  ; Copy ecx into ebx               	                	 dec num               	 cmp num, 0               	jnz here ; Jump if num <> 0               	invoke SetDlgItemInt, hWnd, IDC_EDIT2, eax, FALSE``

Once the loop starts I beleive it enters in an infinite loop (the program crashes), tough I don't know why.

Edit: Fixed.

New code:

``                invoke GetDlgItemInt, hWnd, IDC_EDIT1, NULL, FALSE               	mov edx, eax               	         	               	cmp edx, 0 ; if edx == 0 set zero as IDC_EDIT2               	jz zero               	mov eax, 1               	mov ebx, 1 ; Set initial values               	mov ecx, 0               	               	here:               	 add ecx, eax               	 mov eax, ebx  ; Copy ebx into eax               	 mov ebx, ecx  ; Copy ecx into ebx               	                	 dec edx               	jnz here ; Jump if edx <> 0               	invoke SetDlgItemInt, hWnd, IDC_EDIT2, eax, FALSE               	jmp finish               	               	zero:               	 invoke SetDlgItemInt, hWnd, IDC_EDIT2, 0, FALSE               	finish:``
Posted on 2005-08-16 21:16:02 by Lenin
http://www.asmcommunity.net/board/index.php?topic=14206.0

i meant search on this forum
Posted on 2005-08-17 00:55:20 by evlncrn8
I did...    :roll:
Posted on 2005-08-17 17:31:27 by Lenin