954,490 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Fibonacci sequence

I am using an assembly compiler to try and print the first 12 numbers. I have succeeded in adding, but it won't print some of the numbers.

I want. 1 1 2 3 5 8 13 21 34 55 89 144

BUT GET. 1 2 5 13 34 89 233 610 as my out put.

I am missing some numbers like 3 and 8 ....
Here is my code

TITLE Fibonacci sequence with loop

; Prints first 12 numbers of fibonacci sequence with loop.

INCLUDE Irvine32.inc

.code
main PROC

; mov ax, 0
mov ecx, 12 ; how many times it should loop
mov eax, 1
mov ebx, 0
L1:

add eax, ebx
add ebx, eax
; add ebx, eax

CALL WriteInt


loop L1


exit
main ENDP
END main

torbecire
Light Poster
47 posts since Feb 2007
Reputation Points: 12
Solved Threads: 0
 

the code you wrote is not for such a sequence, try and calculate manually and you'll see, u must write another code. try adding one more register. whats with the numbers anyway?

sgk26p10p07
Newbie Poster
19 posts since Oct 2007
Reputation Points: 10
Solved Threads: 1
 

yea one more register like for instance dx where it will be now
add eax, ebx
add edx,eax ; now write a code that writes using ax, then dx b4 returning
add ebx, eax

sgk26p10p07
Newbie Poster
19 posts since Oct 2007
Reputation Points: 10
Solved Threads: 1
 

Hello,
Thanks a lot I did what you said, and EUREKA. THANKS A LOT.
TITLE Fibonacci sequence with loop

; Prints first 12 numbers of fibonacci sequence with loop.
INCLUDE Irvine32.inc

.code
main PROC

mov ebp, 0
mov edx, 1

mov ebx, edx
mov ecx, 12
L1:
mov eax, edx
mov ebp, eax
mov edx, ebx
add ebx, ebp
; call DumpRegs
call WriteInt
; dec ecx
loop L1
exit
main ENDP
END main

torbecire
Light Poster
47 posts since Feb 2007
Reputation Points: 12
Solved Threads: 0
 

the last code doesnt compile rigght on masm 615..it says:
instruction or register not accepted in current CPU..

Josue198s
Light Poster
28 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

can sum1 help me cum up with a code thaat displays the 1st 15 numbers of the fobonacci code in assembly code with or without input from the user.....pls

Launcelot.anza
Newbie Poster
1 post since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

pano po pag kelangan mgastart sa 0 anu code ang ilalagay?

ynahneng
Newbie Poster
2 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

what code i am going to put to start the number in zero?

ynahneng
Newbie Poster
2 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You