From 78357b8852626b510527f3b8d770a7dd8956fcc7 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 16 Jul 2021 08:38:43 -0700 Subject: . --- html/linux/apps/ex3.2.mu.html | 98 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 html/linux/apps/ex3.2.mu.html (limited to 'html/linux/apps/ex3.2.mu.html') diff --git a/html/linux/apps/ex3.2.mu.html b/html/linux/apps/ex3.2.mu.html new file mode 100644 index 00000000..98c6a027 --- /dev/null +++ b/html/linux/apps/ex3.2.mu.html @@ -0,0 +1,98 @@ + + + + +Mu - linux/apps/ex3.2.mu + + + + + + + + + + +https://github.com/akkartik/mu/blob/main/linux/apps/ex3.2.mu +
+ 1 # Unnecessarily use an array to sum 1..10
+ 2 #
+ 3 # To run:
+ 4 #   $ ./translate apps/ex3.2.mu
+ 5 #   $ ./a.elf
+ 6 #   $ echo $?
+ 7 #   55
+ 8 
+ 9 fn main -> _/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   var result/edx: int <- 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   return result
+33 }
+
+ + + -- cgit 1.4.1-2-gfad0