about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-28 22:41:26 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-28 22:41:26 -0700
commitb22fa8afd813270cfb4639c8bdd9a685488af7f2 (patch)
treef49e225b7bba0f1a763d66de8f8e43d52b423268
parent583a966d3e0b0f0e0fa9166986c877fda0643196 (diff)
downloadmu-b22fa8afd813270cfb4639c8bdd9a685488af7f2.tar.gz
6423 - done with sample app 'print-file'
Observations:
  - the orchestration from 'in' to 'addr-in' to '_in-addr' to 'in-addr'
    is quite painful. Once to turn a handle into its address, once to turn
    a handle into the address of its payload, and a third time to switch
    a variable out of the overloaded 'eax' variable to make room for read-byte-buffered.
  - I'm starting to use SubX as an escape hatch for features missing in Mu:
    - access to syscalls (which pass args in registers)
    - access to global variables
-rw-r--r--103screen.subx25
-rwxr-xr-xapps/mubin256151 -> 256204 bytes
-rw-r--r--apps/print-file.mu16
3 files changed, 35 insertions, 6 deletions
diff --git a/103screen.subx b/103screen.subx
index 75753a1d..944fd4aa 100644
--- a/103screen.subx
+++ b/103screen.subx
@@ -134,6 +134,31 @@ $print-string:end:
     5d/pop-to-ebp
     c3/return
 
+print-byte:  # c: byte
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (write-byte-buffered Stdout *(ebp+8))
+$print-byte:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+# just because Mu has no support for global variables yet
+flush-stdout:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (flush Stdout)
+$flush-stdout:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
 print-int32-to-screen:  # n: int
     # . prologue
     55/push-ebp
diff --git a/apps/mu b/apps/mu
index 1f77f3b4..06f3a21b 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/print-file.mu b/apps/print-file.mu
index b5b5601b..8bec0105 100644
--- a/apps/print-file.mu
+++ b/apps/print-file.mu
@@ -19,13 +19,17 @@ $main-body: {
         var addr-in/eax: (addr handle buffered-file) <- address in
         open *filename, 0, addr-in
       }
-      var in-addr/eax: (addr buffered-file) <- lookup in
-      print-string "filename: "
-      print-string *filename
-      print-string ": "
-      print-int32-to-screen in-addr
-      print-string "\n"
+      var _in-addr/eax: (addr buffered-file) <- lookup in
+      var in-addr/ecx: (addr buffered-file) <- copy _in-addr
+      {
+        var c/eax: byte <- read-byte-buffered in-addr
+        compare c, 0xffffffff
+        break-if-=
+        print-byte c
+        loop
+      }
     }
   }
+  flush-stdout
   exit-status <- copy 0
 }