Website Summary Files Commits Branches @commit @diff @stats
path: root / examples
diff options
context:
space:
mode:
Commit8195dbb65842beb1999717411921cfe3dfb74305 (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-02-15 08:16:47 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-02-15 08:16:47 +0200
Filesbd584bc9fe8525113cf836c4dfdd0c8faeff4184 /examples
tonkobali-8195dbb65842beb1999717411921cfe3dfb74305.tar
tonkobali-8195dbb65842beb1999717411921cfe3dfb74305.tar.gz
tonkobali-8195dbb65842beb1999717411921cfe3dfb74305.zip
Parent34f98003e0a4c39120a177226fbc344d45289c41 (diff)
feat(examples): Add complicated sum, sub and subroutine example
1 files changed, 27 insertions, 0 deletions
-rw-r--r--examples/math.s27
diff --git a/examples/math.s b/examples/math.s
new file mode 100644
index 0000000..2a9c673
--- /dev/null
+++ b/examples/math.s
@@ -0,0 +1,27 @@
+jmp main
+
+sum:
+ mov x, %1000 ; %1000 = x
+ add y, %1000 ; %1000 += y
+ rts
+
+sub:
+ mov x, %1000 ; %1000 = x
+ sub y, %1000 ; %1000 -= y
+ rts
+
+operation = 0 ; 0 for sum, >0 for sub
+x = 48
+y = 7
+main:
+ beq operation, call_sum ; if operation then %1000 = x+y
+ jmp call_sub ; else %1000 = x-y
+
+ call_sum:
+ jsr sum
+ jmp call_end
+ call_sub:
+ jsr sub
+ call_end:
+
+ inc %1001 ; Times main has been ran