1,105,644 Community Members

Fibonacci sequence

Member Avatar
torbecire
Light Poster
46 posts since Feb 2007
Reputation Points: 2 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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
Member Avatar
sgk26p10p07
Newbie Poster
19 posts since Oct 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
sgk26p10p07
Newbie Poster
19 posts since Oct 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
torbecire
Light Poster
46 posts since Feb 2007
Reputation Points: 2 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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
Question Answered as of 6 Years Ago by sgk26p10p07
Member Avatar
Josue198s
Light Poster
28 posts since Aug 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Launcelot.anza
Newbie Poster
1 post since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
ynahneng
Newbie Poster
2 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
ynahneng
Newbie Poster
2 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article