summaryrefslogtreecommitdiff
path: root/base/Factorial.vaporm
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-26 15:50:38 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-26 15:50:38 -0600
commit1851f5e76018ec1df3b55dce6cc9a64c9497bf7a (patch)
tree30f629f7b137a494d4202487f4e22df2d9456481 /base/Factorial.vaporm
parent012298517078170762112abe2654dc69b2f146e1 (diff)
Rearrange directory structure
Diffstat (limited to 'base/Factorial.vaporm')
-rw-r--r--base/Factorial.vaporm40
1 files changed, 40 insertions, 0 deletions
diff --git a/base/Factorial.vaporm b/base/Factorial.vaporm
new file mode 100644
index 0000000..a7e981c
--- /dev/null
+++ b/base/Factorial.vaporm
@@ -0,0 +1,40 @@
+const vmt_Fac
+ :Fac.ComputeFac
+
+func Main [in 0, out 0, local 0]
+ $t0 = HeapAllocZ(4)
+ [$t0] = :vmt_Fac
+ if $t0 goto :null1
+ Error("null pointer")
+null1:
+ $t1 = [$t0]
+ $t1 = [$t1]
+ $a0 = $t0
+ $a1 = 10
+ call $t1
+ $t1 = $v0
+ PrintIntS($t1)
+ ret
+
+func Fac.ComputeFac [in 0, out 0, local 1]
+ local[0] = $s0
+ $t0 = $a0
+ $s0 = $a1
+ $t1 = LtS($s0 1)
+ if0 $t1 goto :if1_else
+ $t1 = 1
+ goto :if1_end
+if1_else:
+ $t2 = [$t0]
+ $t2 = [$t2]
+ $t3 = Sub($s0 1)
+ $a0 = $t0
+ $a1 = $t3
+ call $t2
+ $t3 = $v0
+ $t1 = MulS($s0 $t3)
+if1_end:
+ $v0 = $t1
+ $s0 = local[0]
+ ret
+