First of all hi :),
I'm having problems with the fibonacci formula is ASM, it's easy in C:
Posted on 2005-08-15 23:45:36 by Lenin
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.
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.
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.
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
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))
I tried changing Alone's code to fit my purposes but my code dosen't work...
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 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:
http://www.asmcommunity.net/board/index.php?topic=14206.0
i meant search on this forum
i meant search on this forum
I did... :roll: