From 290f2f677a41b7e5bef5476447132970ad621f4f Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Thu, 12 Mar 2020 01:16:47 -0700 Subject: 6138 --- html/apps/ex3.2.mu.html | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 html/apps/ex3.2.mu.html (limited to 'html/apps') diff --git a/html/apps/ex3.2.mu.html b/html/apps/ex3.2.mu.html new file mode 100644 index 00000000..9807b4f4 --- /dev/null +++ b/html/apps/ex3.2.mu.html @@ -0,0 +1,94 @@ + + + + +Mu - apps/ex3.2.mu + + + + + + + + + + +https://github.com/akkartik/mu/blob/master/apps/ex3.2.mu +
+ 1 # Unnecessarily use an array to sum 1..9
+ 2 #
+ 3 # To run:
+ 4 #   $ ./translate_mu apps/ex3.2.mu
+ 5 #   $ ./a.elf
+ 6 #   $ echo $?
+ 7 #   55
+ 8 
+ 9 fn main -> result/ebx: int {
+10   # populate a
+11   var a: (array int 0xb)  # 11; we waste index 0
+12   var i/ecx: int <- copy 1
+13   {
+14     compare i, 0xb
+15     break-if->=
+16     var x/eax: (addr int) <- index a, i
+17     copy-to *x, i
+18     i <- increment
+19     loop
+20   }
+21   # sum
+22   result <- copy 0
+23   i <- copy 1
+24   {
+25     compare i, 0xb
+26     break-if->=
+27     var x/eax: (addr int) <- index a, i
+28     result <- add *x
+29     i <- increment
+30     loop
+31   }
+32 }
+
+ + + -- cgit 1.4.1-2-gfad0