about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-14 21:14:04 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-14 21:14:04 -0700
commit6b41ca6d95bf6dbafab3fdc85d7355ac8b365931 (patch)
treeffab6daf3af380a661185d9b072d64640194c65c
parent40d40b83decac3d4f9a3da2dc222d19d1ab704f1 (diff)
downloadmu-6b41ca6d95bf6dbafab3fdc85d7355ac8b365931.tar.gz
6777
Print answers in decimal in apps/arith.mu
-rw-r--r--304screen.subx31
-rw-r--r--400.mu2
-rw-r--r--405screen.mu15
-rw-r--r--apps/arith.mu17
-rwxr-xr-xapps/mubin389284 -> 389400 bytes
5 files changed, 56 insertions, 9 deletions
diff --git a/304screen.subx b/304screen.subx
index afed9775..1537a9b1 100644
--- a/304screen.subx
+++ b/304screen.subx
@@ -223,6 +223,37 @@ $print-int32-hex-to-real-screen:end:
     5d/pop-to-ebp
     c3/return
 
+print-int32-decimal-to-real-screen:  # n: int
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (write-int32-decimal-buffered Stdout *(ebp+8))
+    (flush Stdout)
+$print-int32-decimal-to-real-screen:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+write-int32-decimal-buffered:  # f: (addr buffered-file), n: int
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # var ecx: (stream byte 16)
+    81 5/subop/subtract %esp 0x10/imm32
+    68/push 0x10/imm32/size
+    68/push 0/imm32/read
+    68/push 0/imm32/write
+    89/<- %ecx 4/r32/esp
+    (write-int32-decimal %ecx *(ebp+0xc))
+    (write-stream-data *(ebp+8) %ecx)
+$write-int32-decimal-buffered:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
 reset-formatting-on-real-screen:
     # . prologue
     55/push-ebp
diff --git a/400.mu b/400.mu
index 80cd63a0..ab41fc5b 100644
--- a/400.mu
+++ b/400.mu
@@ -146,6 +146,8 @@ sig print-string-to-real-screen s: (addr array byte)
 sig print-stream-to-real-screen s: (addr stream byte)
 sig print-grapheme-to-real-screen c: grapheme
 sig print-int32-hex-to-real-screen n: int
+sig print-int32-decimal-to-real-screen n: int
+sig write-int32-decimal-buffered f: (addr buffered-file), n: int
 sig reset-formatting-on-real-screen
 sig start-color-on-real-screen fg: int, bg: int
 sig start-bold-on-real-screen
diff --git a/405screen.mu b/405screen.mu
index f4171bc8..62bf1005 100644
--- a/405screen.mu
+++ b/405screen.mu
@@ -439,6 +439,21 @@ $print-int32-hex:body: {
 }
 }
 
+fn print-int32-decimal screen: (addr screen), n: int {
+$print-int32-decimal:body: {
+  compare screen, 0
+  {
+    break-if-!=
+    print-int32-decimal-to-real-screen n
+    break $print-int32-decimal:body
+  }
+  {
+    break-if-=
+    # fake screen
+  }
+}
+}
+
 fn reset-formatting screen: (addr screen) {
 $reset-formatting:body: {
   compare screen, 0
diff --git a/apps/arith.mu b/apps/arith.mu
index ebc9850c..fdf97213 100644
--- a/apps/arith.mu
+++ b/apps/arith.mu
@@ -4,7 +4,6 @@
 #   https://compilers.iecc.com/crenshaw
 #
 # Limitations:
-#   Reads numbers in decimal, but prints numbers in hex :(
 #   No division yet.
 #
 # To build:
@@ -14,19 +13,19 @@
 #   $ ./a.elf
 #   press ctrl-c or ctrl-d to exit
 #   > 1
-#   0x00000001
+#   1
 #   > 1+1
-#   0x00000002
+#   2
 #   > 1 + 1
-#   0x00000002
+#   2
 #   > 1+2 +3
-#   0x00000006
+#   6
 #   > 1+2 *3
-#   0x00000007
+#   7
 #   > (1+2) *3
-#   0x00000009
+#   9
 #   > 1 + 3*4
-#   0x0000000d
+#   13
 #   > ^D
 #   $
 #
@@ -46,7 +45,7 @@ fn main -> exit-status/ebx: int {
     compare look, 0
     break-if-=
     # print
-    print-int32-hex 0, n
+    print-int32-decimal 0, n
     print-string 0, "\n"
     #
     loop
diff --git a/apps/mu b/apps/mu
index e44e8e4e..5bb5022e 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differ