Website Summary Files Commits Branches @commit @diff @stats
path: root / examples / fib.s
blob: afc4b254119481a169a2a13f8986c404ff1e85f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
f0 = 0
f1 = 1
fN = 0
n  = 5

fib:
	beq n, fib_result ; while n > 0

	mov f0, fN        ; fN = f0 + f1
	add f1, fN
	mov f1, f0        ; f0 = f1
	mov fN, f1        ; f1 = fN

	dec n             ; n--

	jmp fib

fib_result:
	mov f0, %1000     ; return f0
	mov %0, f0        ; Reset f0
	mov %1, f1        ; Reset f1