From 8195dbb65842beb1999717411921cfe3dfb74305 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 15 Feb 2025 08:16:47 +0200 Subject: feat(examples): Add complicated sum, sub and subroutine example --- examples/math.s | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/math.s (limited to 'examples/math.s') 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 -- cgit v1.3.1-26-gb76a