about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-01-29 23:17:36 -0800
committerKartik Agaram <vc@akkartik.com>2020-01-29 23:17:36 -0800
commitea62afb1dae6ded38b34689917ee520f6094edc2 (patch)
tree15ad72acac446a089d126aa961f5859650f21362 /apps
parent264cef5ed4cadea34b188f241a3f4490f133eedb (diff)
downloadmu-ea62afb1dae6ded38b34689917ee520f6094edc2.tar.gz
5954 - 'factorial' working!
Diffstat (limited to 'apps')
-rw-r--r--apps/factorial.mu19
1 files changed, 19 insertions, 0 deletions
diff --git a/apps/factorial.mu b/apps/factorial.mu
new file mode 100644
index 00000000..f306de25
--- /dev/null
+++ b/apps/factorial.mu
@@ -0,0 +1,19 @@
+fn main -> result/ebx: int {
+  var tmp/eax: int <- factorial 5
+  result <- copy tmp
+}
+
+fn factorial n: int -> result/eax: int {
+  compare n 1
+  {
+    break-if->
+    result <- copy 1
+  }
+  {
+    break-if-<=
+    var tmp/ecx: int <- copy n
+    tmp <- decrement
+    result <- factorial tmp
+    result <- multiply n
+  }
+}