about summary refs log tree commit diff stats
path: root/310copy-bytes.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-07 13:51:54 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-07 14:18:48 -0700
commit5462619d963ca8606c03812b1d8d614bb7e0462c (patch)
tree9dc81e5f27dedb337f09ea130b2d7b8220bc6c89 /310copy-bytes.subx
parent9f293fef05217b9d7aabe7f697022145ada5bf47 (diff)
downloadmu-5462619d963ca8606c03812b1d8d614bb7e0462c.tar.gz
6742 - support for formatting in fake screens
We still need a few primitives, but we can implement these as needed. I'm
ready to call the fake screen done.
Diffstat (limited to '310copy-bytes.subx')
-rw-r--r--310copy-bytes.subx57
1 files changed, 57 insertions, 0 deletions
diff --git a/310copy-bytes.subx b/310copy-bytes.subx
new file mode 100644
index 00000000..f33388a9
--- /dev/null
+++ b/310copy-bytes.subx
@@ -0,0 +1,57 @@
+# Fill a region of memory with zeroes.
+
+== code
+
+copy-bytes:  # src: (addr byte), dest: (addr byte), size: int
+    # pseudocode:
+    #   curr-src/esi = src
+    #   curr-dest/edi = dest
+    #   i/ecx = 0
+    #   while true
+    #     if (i >= size) break
+    #     *curr-dest = *curr-src
+    #     ++curr-src
+    #     ++curr-dest
+    #     ++i
+    #
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
+    51/push-ecx
+    52/push-edx
+    56/push-esi
+    57/push-edi
+    # curr-src/esi = src
+    8b/-> *(ebp+8) 6/r32/esi
+    # curr-dest/edi = dest
+    8b/-> *(ebp+0xc) 7/r32/edi
+    # var i/ecx: int = 0
+    b9/copy-to-ecx 0/imm32
+    # edx = size
+    8b/-> *(ebp+0x10) 2/r32/edx
+    {
+      # if (i >= size) break
+      39/compare %ecx 2/r32/edx
+      7d/jump-if->=  break/disp8
+      # *curr-dest = *curr-src
+      8a/byte-> *esi 0/r32/AL
+      88/byte<- *edi 0/r32/AL
+      # update
+      46/increment-esi
+      47/increment-edi
+      41/increment-ecx
+      eb/jump loop/disp8
+    }
+$copy-bytes:end:
+    # . restore registers
+    5f/pop-to-edi
+    5e/pop-to-esi
+    5a/pop-to-edx
+    59/pop-to-ecx
+    58/pop-to-eax
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return