1.11M Members

Fibonacci sequence

 
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
 
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?

 
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

 
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
 
0
 

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

 
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

 
0
 

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

 
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