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

Recommended Answers

All 7 Replies

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?

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

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
commented: Thanks for helping me along on this problem, I too needed another register to accomplish the same goal. +2
Member Avatar for Josue198s

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

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.