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
5
Contributors
7
Replies
9
Views
9 Years
Discussion Span
Last Post by ynahneng
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
Votes + Comments
Thanks for helping me along on this problem, I too needed another register to accomplish the same goal.
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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.