about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-06-15 18:05:23 -0700
committerKartik Agaram <vc@akkartik.com>2020-06-15 18:05:23 -0700
commit5fe0bc16884c0f16f173db55a7f59a9738e67f02 (patch)
tree8ef7bb5e830584238810c02fd6316b2c88df047e /apps
parent538805df510df440b5396a15a5ed8869ea8f5df7 (diff)
downloadmu-5fe0bc16884c0f16f173db55a7f59a9738e67f02.tar.gz
6531
Diffstat (limited to 'apps')
-rw-r--r--apps/arith.mu42
1 files changed, 17 insertions, 25 deletions
diff --git a/apps/arith.mu b/apps/arith.mu
index e5d1be18..6d0307ee 100644
--- a/apps/arith.mu
+++ b/apps/arith.mu
@@ -1,39 +1,31 @@
-fn main args: (addr array (addr array byte)) -> exit-status/ebx: int {
-  # var input/esi: (addr array byte) = args[1] {{{
-  var input/esi: (addr array byte) <- copy 0
-  {
-    var args-in-reg/eax: (addr array (addr array byte)) <- copy args
-    var input-in-eax/eax: (addr addr array byte) <- index args-in-reg, 1
-    input <- copy *input-in-eax
-  }
-  # }}}
-  var result/eax: int <- parse-int input
-  exit-status <- copy result  # only LSB makes it out
+fn main -> exit-status/ebx: int {
+  var val/eax: int <- num
+  print-int32-to-screen val
+  print-string "\n"
+  exit-status <- copy 0
 }
 
-fn parse-int _in: (addr array byte) -> result/eax: int {
-  var in/esi: (addr array byte) <- copy _in
-  var len/edx: int <- length in
-  var i/ecx: int <- copy 0
+fn num -> result/eax: int {
   var out/edi: int <- copy 0
   {
-    compare i, len
-    break-if->=
+    var c/eax: byte <- read-key
+    # if (c == EOF) break
+    compare c, 0xffffffff  # EOF marker
+    break-if-=
+    # if (c == ' ') break
+    compare c, 0x20  # space
+    break-if-=
+    # if (c == '\n') break
+    compare c, 0xa  # newline
+    break-if-=
     # out *= 10
     {
       var ten/eax: int <- copy 0xa
       out <- multiply ten
     }
-    # c = in[i]
-    var c/eax: byte <- copy 0
-    {
-      var tmp/ebx: (addr byte) <- index in, i
-      c <- copy-byte *tmp
-    }
-    #
+    # out += digit(c)
     var digit/eax: int <- to-decimal-digit c
     out <- add digit
-    i <- increment
     loop
   }
   result <- copy out