about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-12-02 11:08:30 -0800
committerKartik Agaram <vc@akkartik.com>2018-12-02 11:08:30 -0800
commitf44c595267ba1dc6b076340e300961c304904408 (patch)
tree2844e405bb4d3b156e21377db2277f5120d80ce3 /subx
parente4ac3c9e6e5464a0fc0f8fd3763a572e0e180c04 (diff)
downloadmu-f44c595267ba1dc6b076340e300961c304904408.tar.gz
4815
Diffstat (limited to 'subx')
-rw-r--r--subx/apps/crenshaw2-1.subx13
-rw-r--r--subx/apps/crenshaw2-1b.subx13
2 files changed, 18 insertions, 8 deletions
diff --git a/subx/apps/crenshaw2-1.subx b/subx/apps/crenshaw2-1.subx
index b202f25f..c523634a 100644
--- a/subx/apps/crenshaw2-1.subx
+++ b/subx/apps/crenshaw2-1.subx
@@ -30,6 +30,10 @@
 # . 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
 
+#?     # for debugging: run a single test; don't bother setting status code
+#?     e8/call test-get-num-reads-single-digit/disp32
+#?     eb/jump  $main:end/disp8
+
 # main: run tests if necessary, call 'compile' if not
     # . prolog
     89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
@@ -50,7 +54,6 @@
     75/jump-if-not-equal  $run-main/disp8
     # . run-tests()
     e8/call  run-tests/disp32
-#?     e8/call test-get-num-reads-multiple-digits/disp32
     8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/EBX   Num-test-failures/disp32          # copy *Num-test-failures to EBX
     eb/jump  $main:end/disp8
 $run-main:
@@ -94,13 +97,14 @@ compile:  # in : (address buffered-file), out : fd or (address stream), err : fd
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
     # var num/ECX : (address stream) on the stack
     # Numbers can be 32 bits or 8 hex bytes long. One of them will be in 'Look', so we need space for 7 bytes.
-    # We won't add more, so that we can get overflow-handling for free.
+    # Sizing the stream just right buys us overflow-handling for free inside 'get-num'.
     # Add 12 bytes for 'read', 'write' and 'length' fields, for a total of 19 bytes, or 0x13 in hex.
+    # The stack pointer is no longer aligned, so dump_stack() can be misleading past this point.
     81          5/subop/subtract    3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x13/imm32        # subtract from ESP
     8d/copy-address                 0/mod/indirect  4/rm32/sib    4/base/ESP  4/index/none  .           1/r32/ECX   .               .                 # copy ESP to ECX
-    # num->length = 7
+    # initialize the stream
+    # . num->length = 7
     c7/copy                         1/mod/*+disp8   1/rm32/ECX    .           .             .           .           8/disp8         7/imm32           # copy to *(ECX+8)
-    # read a digit from 'in' into 'num'
     # . clear-stream(num)
     # . . push args
     51/push-ECX
@@ -108,6 +112,7 @@ compile:  # in : (address buffered-file), out : fd or (address stream), err : fd
     e8/call  clear-stream/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # read a digit from 'in' into 'num'
     # . get-num(in, num, err, ed)
     # . . push args
     ff          6/subop/push        1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           .           0x14/disp8      .                 # push *(EBP+20)
diff --git a/subx/apps/crenshaw2-1b.subx b/subx/apps/crenshaw2-1b.subx
index a3c56ed5..1baf90c3 100644
--- a/subx/apps/crenshaw2-1b.subx
+++ b/subx/apps/crenshaw2-1b.subx
@@ -30,6 +30,10 @@
 # . 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
 
+#?     # for debugging: run a single test; don't bother setting status code
+#?     e8/call test-get-num-reads-single-digit/disp32
+#?     eb/jump  $main:end/disp8
+
 # main: run tests if necessary, call 'compile' if not
     # . prolog
     89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
@@ -50,7 +54,6 @@
     75/jump-if-not-equal  $run-main/disp8
     # . run-tests()
     e8/call  run-tests/disp32
-#?     e8/call test-get-num-reads-multiple-digits/disp32
     8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/EBX   Num-test-failures/disp32          # copy *Num-test-failures to EBX
     eb/jump  $main:end/disp8
 $run-main:
@@ -95,13 +98,14 @@ compile:  # in : (address buffered-file), out : fd or (address stream), err : fd
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
     # var num/ECX : (address stream) on the stack
     # Numbers can be 32 bits or 8 hex bytes long. One of them will be in 'Look', so we need space for 7 bytes.
-    # We won't add more, so that we can get overflow-handling for free.
+    # Sizing the stream just right buys us overflow-handling for free inside 'get-num'.
     # Add 12 bytes for 'read', 'write' and 'length' fields, for a total of 19 bytes, or 0x13 in hex.
+    # The stack pointer is no longer aligned, so dump_stack() can be misleading past this point.
     81          5/subop/subtract    3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x13/imm32        # subtract from ESP
     8d/copy-address                 0/mod/indirect  4/rm32/sib    4/base/ESP  4/index/none  .           1/r32/ECX   .               .                 # copy ESP to ECX
-    # num->length = 7
+    # initialize the stream
+    # . num->length = 7
     c7/copy                         1/mod/*+disp8   1/rm32/ECX    .           .             .           .           8/disp8         7/imm32           # copy to *(ECX+8)
-    # read a digit from 'in' into 'num'
     # . clear-stream(num)
     # . . push args
     51/push-ECX
@@ -109,6 +113,7 @@ compile:  # in : (address buffered-file), out : fd or (address stream), err : fd
     e8/call  clear-stream/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # read a digit from 'in' into 'num'
     # . get-num(in, num, err, ed)
     # . . push args
     ff          6/subop/push        1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           .           0x14/disp8      .                 # push *(EBP+20)