Website Summary Files Commits Branches @commit @diff @stats
path: root / examples
diff options
context:
space:
mode:
1 files changed, 21 insertions, 0 deletions
-rw-r--r--examples/fib.s21
diff --git a/examples/fib.s b/examples/fib.s
new file mode 100644
index 0000000..afc4b25
--- /dev/null
+++ b/examples/fib.s
@@ -0,0 +1,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