Virtual Assembler - Learn assembly languages fast!

Miscellaneous Forums/Blitz Showcase/Virtual Assembler - Learn assembly languages fast!

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Ah, cool! Then, here's an updated fibonacci function which handles fib(0) as well:

	mov eax, 1

; In: eax = n
; Out: ecx = fib(n)
	mov	ecx, 1
	cmp	eax, 0
	jle	end
	mov	ebx, 0
loop:	mov	edx, ebx
	add	edx, ecx
	mov	ebx, ecx
	mov	ecx, edx
	dec	eax
	cmp	eax, 0
	jg	loop

end:	invoke	print, ecx


Just change the initial eax to something else to see different results. :)

(Oh, and you can't change the add to an inc. ecx is updated with a new value in each loop.)