about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-03-12 01:16:47 -0700
committerKartik Agaram <vc@akkartik.com>2020-03-12 01:16:47 -0700
commit290f2f677a41b7e5bef5476447132970ad621f4f (patch)
tree1af325901d710293c2006cd44156a323a16041e2 /apps
parent8f32cb825ee4037ad4cf0d7d3f3a48093dc5eb7f (diff)
downloadmu-290f2f677a41b7e5bef5476447132970ad621f4f.tar.gz
6138
Diffstat (limited to 'apps')
-rw-r--r--apps/ex3.2.mu32
1 files changed, 32 insertions, 0 deletions
diff --git a/apps/ex3.2.mu b/apps/ex3.2.mu
new file mode 100644
index 00000000..2a2432c7
--- /dev/null
+++ b/apps/ex3.2.mu
@@ -0,0 +1,32 @@
+# Unnecessarily use an array to sum 1..9
+#
+# To run:
+#   $ ./translate_mu apps/ex3.2.mu
+#   $ ./a.elf
+#   $ echo $?
+#   55
+
+fn main -> result/ebx: int {
+  # populate a
+  var a: (array int 0xb)  # 11; we waste index 0
+  var i/ecx: int <- copy 1
+  {
+    compare i, 0xb
+    break-if->=
+    var x/eax: (addr int) <- index a, i
+    copy-to *x, i
+    i <- increment
+    loop
+  }
+  # sum
+  result <- copy 0
+  i <- copy 1
+  {
+    compare i, 0xb
+    break-if->=
+    var x/eax: (addr int) <- index a, i
+    result <- add *x
+    i <- increment
+    loop
+  }
+}