CSC231 Fibonaccis

From dftwiki3
Revision as of 10:25, 26 September 2012 by Thiebaut (talk | contribs) (Created page with "--~~~~ ---- <source lang="asm"> ;;; fibonacci.asm ;;; D. Thiebaut ;;; simple program computing the first 5 fibonacci terms without ;;; using a loop. ;;; Each term is stored in a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut 10:25, 26 September 2012 (EDT)


;;; fibonacci.asm
;;; D. Thiebaut
;;; simple program computing the first 5 fibonacci terms without
;;; using a loop.
;;; Each term is stored in a double word.
;;;

		section	.data
fib		dd	0, 0, 0, 0, 0

	
		section	.text
		global	_start
_start:
		mov	dword[fib], 1		 ; fib[0] <- 1
		mov	dword[fib+4], 1		 ; fib[1] <- 1
		mov	eax, dword[fib]		 ; eax <- fib[0]
	
		add	eax, dword[fib+4] 	 ; eax <- fib[0]+fib[1]
		mov	dword[fib+8], eax	 ; fib[2] <- eax

		add	eax, dword[fib+4]  	 ; eax <- fib[2] + fib[1]
		mov	dword[fib+12], eax 	 ; fib[3] <- eax

		add	eax, dword[fib+8] 	 ; eax <- fib[3] + fib[2] 
		mov	dword[fib+16], eax	 ; fib[4] <- eax

;;; exit
		mov	ebx, 0
		mov	eax, 1
		int	0x80