aboutsummaryrefslogtreecommitdiffstats
path: root/test/e2e/fibo/fibo.atk16
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2024-02-22 08:52:20 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2024-02-22 08:52:20 +0200
commit416e896956d3b05793337da6609fe1544797c0a9 (patch)
tree9fa0cf3b622d4c9c086e4c08c5011ab12fdd4a77 /test/e2e/fibo/fibo.atk16
parentaefe0cf3874c542669051b2b3cc21c9590aa970b (diff)
Add stuff, refactor
Diffstat (limited to 'test/e2e/fibo/fibo.atk16')
-rw-r--r--test/e2e/fibo/fibo.atk1653
1 files changed, 53 insertions, 0 deletions
diff --git a/test/e2e/fibo/fibo.atk16 b/test/e2e/fibo/fibo.atk16
new file mode 100644
index 0000000..608b4d1
--- /dev/null
+++ b/test/e2e/fibo/fibo.atk16
@@ -0,0 +1,53 @@
+; bootstrap code (must be called to setup mandatory data)
+; will jump to label main
+@include bootstrap
+
+@label main
+; call fibo subroutine with parameter 10
+ ldi 10 RA
+ spush RA
+ call fibo
+ spop RA
+ hlt
+
+@label fibo
+; % n -> % result
+
+; store RB, RC on stack
+ spush RB
+ spush RC
+; if n < 2, return n
+ subi RA 2 RA
+ bri sign fibo_early
+; store also RD on stack
+ spush RD
+; a = 0
+ ldi 0 RB
+; b = 1
+ ldi 1 RC
+@label fibo_loop
+; v = a + b
+ add RB RC RD
+; a = b
+ mov RC RB
+; b = v
+ mov RD RC
+; n -= 1
+ dec RA
+; loop while n > 0
+ bri zero fibo_done
+ jpi fibo_loop
+@label fibo_early
+; restore used registers
+ spop RC
+ spop RB
+; return from subroutine
+ return
+@label fibo_done
+ mov RD RA
+; restore used registers
+ spop RD
+ spop RC
+ spop RB
+; return from subroutine
+ return