about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--subx/076zero-out.subx84
-rwxr-xr-xsubx/apps/assortbin32098 -> 32242 bytes
-rwxr-xr-xsubx/apps/crenshaw2-1bin23725 -> 23839 bytes
-rwxr-xr-xsubx/apps/crenshaw2-1bbin24284 -> 24398 bytes
-rwxr-xr-xsubx/apps/dquotesbin38451 -> 38595 bytes
-rwxr-xr-xsubx/apps/factorialbin22641 -> 22755 bytes
-rwxr-xr-xsubx/apps/handlebin23500 -> 23614 bytes
-rwxr-xr-xsubx/apps/hexbin26734 -> 26848 bytes
-rwxr-xr-xsubx/apps/packbin44464 -> 44608 bytes
-rw-r--r--subx/apps/subx-common.subx19
-rwxr-xr-xsubx/apps/surveybin38602 -> 38746 bytes
11 files changed, 103 insertions, 0 deletions
diff --git a/subx/076zero-out.subx b/subx/076zero-out.subx
new file mode 100644
index 00000000..bc19dc21
--- /dev/null
+++ b/subx/076zero-out.subx
@@ -0,0 +1,84 @@
+# Fill a region of memory with zeroes.
+
+== code
+#   instruction                     effective address                                                   register    displacement    immediate
+# . op          subop               mod             rm32          base        index         scale       r32
+# . 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes
+
+zero-out:  # start : address, len : int
+    # pseudocode:
+    #   curr/ESI = start
+    #   i/ECX = 0
+    #   while true
+    #     if (i >= len) break
+    #     *curr = 0
+    #     ++curr
+    #     ++i
+    #
+    # . prolog
+    55/push-EBP
+    89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
+    # . save registers
+    50/push-EAX
+    51/push-ECX
+    52/push-EDX
+    56/push-ESI
+    # curr/ESI = start
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           6/r32/ESI   8/disp8         .                 # copy *(EBP+8) to ESI
+    # i/ECX = 0
+    31/xor                          3/mod/direct    1/rm32/ECX    .           .             .           1/r32/ECX   .               .                 # clear ECX
+    # EDX = len
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           2/r32/EDX   0xc/disp8       .                 # copy *(EBP+12) to EDX
+$zero-out:loop:
+    # if (i >= len) break
+    39/compare                      3/mod/direct    1/rm32/ECX    .           .             .           2/r32/EDX   .               .                 # compare ECX with EDX
+    7d/jump-if-greater-or-equal  $zero-out:end/disp8
+    # *curr = 0
+    c6          0/subop/copy        0/mod/direct    6/rm32/ESI    .           .             .           .           .               0/imm8            # copy byte to *ESI
+    # ++curr
+    46/increment-ESI
+    # ++i
+    41/increment-ECX
+    eb/jump  $zero-out:loop/disp8
+$zero-out:end:
+    # . restore registers
+    5e/pop-to-ESI
+    5a/pop-to-EDX
+    59/pop-to-ECX
+    58/pop-to-EAX
+    # . epilog
+    89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
+    5d/pop-to-EBP
+    c3/return
+
+test-zero-out:
+    # . prolog
+    55/push-EBP
+    89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
+    # region/ECX = 34, 35, 36, 37
+    68/push  0x37363534/imm32
+    89/copy                         3/mod/direct    1/rm32/ECX    .           .             .           4/r32/ESP   .               .                 # copy ESP to ECX
+    # zero-out(ECX, 3)
+    # . . push args
+    68/push  3/imm32/len
+    51/push-ECX
+    # . . call
+    e8/call  zero-out/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # first 3 bytes cleared, fourth left alone
+    # . check-ints-equal(*ECX, 0x37000000, msg)
+    # . . push args
+    68/push  "F - test-zero-out"/imm32
+    68/push  0x37000000/imm32
+    ff          6/subop/push        0/mod/indirect  1/rm32/ECX    .           .             .           .           .               .                 # push *ECX
+    # . . call
+    e8/call  check-ints-equal/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    # . epilog
+    89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
+    5d/pop-to-EBP
+    c3/return
+
+# . . vim:nowrap:textwidth=0
diff --git a/subx/apps/assort b/subx/apps/assort
index dc437fba..83a063f0 100755
--- a/subx/apps/assort
+++ b/subx/apps/assort
Binary files differdiff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1
index 2dc6e6d4..e5e6560c 100755
--- a/subx/apps/crenshaw2-1
+++ b/subx/apps/crenshaw2-1
Binary files differdiff --git a/subx/apps/crenshaw2-1b b/subx/apps/crenshaw2-1b
index efa0ece7..eebd667a 100755
--- a/subx/apps/crenshaw2-1b
+++ b/subx/apps/crenshaw2-1b
Binary files differdiff --git a/subx/apps/dquotes b/subx/apps/dquotes
index c803fa9e..e982690c 100755
--- a/subx/apps/dquotes
+++ b/subx/apps/dquotes
Binary files differdiff --git a/subx/apps/factorial b/subx/apps/factorial
index 2433b2a6..55a59123 100755
--- a/subx/apps/factorial
+++ b/subx/apps/factorial
Binary files differdiff --git a/subx/apps/handle b/subx/apps/handle
index d1cbb74b..3ea729c6 100755
--- a/subx/apps/handle
+++ b/subx/apps/handle
Binary files differdiff --git a/subx/apps/hex b/subx/apps/hex
index 5bfa5863..315e855c 100755
--- a/subx/apps/hex
+++ b/subx/apps/hex
Binary files differdiff --git a/subx/apps/pack b/subx/apps/pack
index 8eff81dd..7ad19415 100755
--- a/subx/apps/pack
+++ b/subx/apps/pack
Binary files differdiff --git a/subx/apps/subx-common.subx b/subx/apps/subx-common.subx
index e8b3140c..129c9821 100644
--- a/subx/apps/subx-common.subx
+++ b/subx/apps/subx-common.subx
@@ -24,6 +24,7 @@ get-or-insert:  # table : (address stream {string, _}), key : (address string),
     #     curr += row-size
     #   if table->write >= table->length
     #     abort
+    #   zero-out(max, row-size)
     #   *max = key
     #   table->write += row-size
     #   return max+4
@@ -72,6 +73,14 @@ $get-or-insert:not-found:
     8b/copy                         0/mod/indirect  6/rm32/ESI    .           .             .           1/r32/ECX   .               .                 # copy *ESI to ECX
     3b/compare                      1/mod/*+disp8   6/rm32/ESI    .           .             .           1/r32/ECX   8/disp8         .                 # compare ECX with *(ESI+8)
     73/jump-if-greater-or-equal-unsigned  $get-or-insert:abort/disp8
+    # zero-out(max, row-size)
+    # . . push args
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x10/disp8      .                 # push *(EBP+16)
+    52/push-EDX
+    # . . call
+    e8/call  zero-out/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # *max = key
     # . EAX = key
     8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           0/r32/EAX   0xc/disp8       .                 # copy *(EBP+12) to EAX
@@ -258,6 +267,7 @@ $test-get-or-insert:end:
 # scan 'table' for a row with a key 'key' and return the address of the corresponding value
 # if no row is found, save 'key' in the next available row
 # if there are no rows free, abort
+# WARNING: leaks memory
 # TODO: pass in an allocation descriptor
 get-or-insert-slice:  # table : (address stream {string, _}), key : (address slice), row-size : int -> EAX : (address _)
     # pseudocode:
@@ -269,6 +279,7 @@ get-or-insert-slice:  # table : (address stream {string, _}), key : (address sli
     #     curr += row-size
     #   if table->write >= table->length
     #     abort
+    #   zero-out(max, row-size)
     #   *max = slice-to-string(Heap, key)
     #   table->write += row-size
     #   return max+4
@@ -317,6 +328,14 @@ $get-or-insert-slice:not-found:
     8b/copy                         0/mod/indirect  6/rm32/ESI    .           .             .           1/r32/ECX   .               .                 # copy *ESI to ECX
     3b/compare                      1/mod/*+disp8   6/rm32/ESI    .           .             .           1/r32/ECX   8/disp8         .                 # compare ECX with *(ESI+8)
     7d/jump-if-greater-or-equal  $get-or-insert-slice:abort/disp8
+    # zero-out(max, row-size)
+    # . . push args
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x10/disp8      .                 # push *(EBP+16)
+    52/push-EDX
+    # . . call
+    e8/call  zero-out/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # *max = slice-to-string(Heap, key)
     # . EAX = slice-to-string(Heap, key)
     # . . push args
diff --git a/subx/apps/survey b/subx/apps/survey
index 9290e1ae..0c900562 100755
--- a/subx/apps/survey
+++ b/subx/apps/survey
Binary files differ