about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-03-14 01:06:27 -0700
committerKartik Agaram <vc@akkartik.com>2020-03-14 01:06:27 -0700
commit9428990bd6e61988df23811205504a5c63a348e1 (patch)
treef655a395122dd58b555d0ec6b506d29b8bc6be3d /apps
parentb7b24ec242b67614e0ab01b681cdfd90b28a4095 (diff)
downloadmu-9428990bd6e61988df23811205504a5c63a348e1.tar.gz
6143
Diffstat (limited to 'apps')
-rw-r--r--apps/factorial.mu2
-rw-r--r--apps/factorial4.subx12
2 files changed, 8 insertions, 6 deletions
diff --git a/apps/factorial.mu b/apps/factorial.mu
index 128ac9ad..722c9e6c 100644
--- a/apps/factorial.mu
+++ b/apps/factorial.mu
@@ -2,6 +2,8 @@
 #   ./translate_mu apps/factorial.mu
 #   ./a.elf test  # to run tests
 #   ./a.elf       # to run factorial(5)
+#
+# Compare apps/factorial4.subx
 
 fn factorial n: int -> result/eax: int {
   compare n 1
diff --git a/apps/factorial4.subx b/apps/factorial4.subx
index 9ab7038f..3aae0dd3 100644
--- a/apps/factorial4.subx
+++ b/apps/factorial4.subx
@@ -60,7 +60,7 @@ factorial:  # n: int -> int/eax
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # save registers
-    53/push-ebx
+    51/push-ecx
     # if (n <= 1) return 1
     81 7/subop/compare *(ebp+8) 1/imm32
     {
@@ -70,14 +70,14 @@ factorial:  # n: int -> int/eax
     # if (n > 1) return n * factorial(n-1)
     {
       7e/jump-if-<= break/disp8
-      # var ebx: int = n-1
-      8b/-> *(ebp+8) 3/r32/ebx
-      4b/decrement-ebx
-      (factorial %ebx)  # => eax
+      # var tmp/ecx: int = n-1
+      8b/-> *(ebp+8) 1/r32/ecx
+      49/decrement-ecx
+      (factorial %ecx)  # => eax
       f7 4/subop/multiply-into-eax *(ebp+8)
     }
     # restore registers
-    5b/pop-to-ebx
+    59/pop-to-ecx
     # . epilogue
     89/<- %esp 5/r32/ebp
     5d/pop-to-ebp