The Fibonacci sequence is a sequence    Fn    of natural numbers defined recursively:

      F0 = 0 
      F1 = 1 
      Fn = Fn-1 + Fn-2, if n>1 



Task

Write a function to generate the    nth    Fibonacci number.

Solutions can be iterative or recursive (though recursive solutions are generally considered too slow and are mostly used as an exercise in recursion).

The sequence is sometimes extended into negative numbers by using a straightforward inverse of the positive definition:

      Fn = Fn+2 - Fn+1, if n<0   

support for negative      n      in the solution is optional.



Related tasks

   Fibonacci n-step number sequences‎
   Leonardo numbers


References

   Wikipedia, Fibonacci number
   Wikipedia, Lucas number
   MathWorld, Fibonacci Number
   Some identities for r-Fibonacci numbers
   OEIS Fibonacci numbers
   OEIS Lucas numbers


TITLE i hate visual studio 4			(Fibs.asm)
;       __         __/--------\
;      >__ \      /  |        |\
;         \  \___/ @  \      /   \__________________
;           \____       \  /                         \\\
;                \____         Coded with love by:    |||
;                      \      Alexander Alvonellos    |||
;                       |          9/29/2011         / ||
;                       |                           |  MM
;                       |      |--------------|     |
;                       |<     |              |<    |
;                       |      |              |     |
;                       |mmmmmm|              |mmmmm|
;; Epic Win. 
 
INCLUDE Irvine32.inc
 
.data
	BEERCOUNT = 48;
	Fibs dd 0, 1, BEERCOUNT DUP(0);
 
.code
main PROC
; I am not responsible for this code.
; They made me write it, against my will.
	;Here be dragons
	mov esi, offset Fibs; offset array;  ;;were to start (start)
	mov ecx, BEERCOUNT; 		;;count of items (how many)
	mov ebx, 4; 		;;size (in number of bytes)
	call DumpMem;
 
	mov ecx, BEERCOUNT; 	;//http://www.wolframalpha.com/input/?i=F ib%5B47%5D+%3E+4294967295
	mov esi, offset Fibs
	NextPlease:;
		mov eax, [esi]; 	;//Get me the data from location at ESI
		add eax, [esi+4];	;//add into the eax the data at esi + another double (next mem loc)
		mov [esi+8], eax;	;//Move that data into the memory location after the second number
		add esi, 4;			;//Update the pointer
	loop NextPlease;	;//Thank you sir, may I have another?
 
 
	;Here be dragons
	mov esi, offset Fibs; offset array;  ;;were to start (start)
	mov ecx, BEERCOUNT; 		;;count of items (how many)
	mov ebx, 4; 		;;size (in number of bytes)
	call DumpMem;
 
	exit		; exit to operating system
main ENDP
 
END main