about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--apps/factorial.mu41
1 files changed, 21 insertions, 20 deletions
diff --git a/apps/factorial.mu b/apps/factorial.mu
index de5bcf54..fe435a53 100644
--- a/apps/factorial.mu
+++ b/apps/factorial.mu
@@ -2,6 +2,27 @@
 #   ./translate_mu apps/factorial.mu
 #   ./a.elf test  # to run tests
 #   ./a.elf       # to run factorial(5)
+
+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
+  }
+}
+
+fn test-factorial {
+  var result/eax: int <- factorial 5
+  check-ints-equal result 0x78 "F - test-factorial"
+}
+
 fn main args: (addr array kernel-string) -> exit-status/ebx: int {
   var a/eax: (addr array kernel-string) <- copy args
   var tmp/ecx: int <- length a
@@ -26,23 +47,3 @@ fn main args: (addr array kernel-string) -> exit-status/ebx: int {
     }
   }
 }
-
-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
-  }
-}
-
-fn test-factorial {
-  var result/eax: int <- factorial 5
-  check-ints-equal result 0x78 "F - test-factorial"
-}