about summary refs log tree commit diff stats
path: root/apps/desugar.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-08-25 00:32:24 -0700
committerKartik Agaram <vc@akkartik.com>2019-08-25 00:32:24 -0700
commit380fc367b8b17c98e3a0472675149e4c669eb9b4 (patch)
tree314f94d593f30f4f06a1b69f1fc3b725a60569fd /apps/desugar.subx
parentd230393c924276a8bb3d9661dff688d5b07705ff (diff)
downloadmu-380fc367b8b17c98e3a0472675149e4c669eb9b4.tar.gz
parsing *(reg-disp)
Diffstat (limited to 'apps/desugar.subx')
-rw-r--r--apps/desugar.subx66
1 files changed, 66 insertions, 0 deletions
diff --git a/apps/desugar.subx b/apps/desugar.subx
index dc36f401..cbd8a408 100644
--- a/apps/desugar.subx
+++ b/apps/desugar.subx
@@ -1494,6 +1494,7 @@ parse-effective-address:  # word : (address slice) -> base/EAX, index/ECX, scale
     #   read register into base
     #   skip whitespace
     #   if (*word->start == ')') goto end
+    #   if (*word->start == '-') goto displacement
     #   if (*word->start != '+') goto error2
     #   ++word->start to skip '+'
     #   skip whitespace
@@ -1594,6 +1595,9 @@ $parse-effective-address:compound-expression:
     81          4/subop/and         3/mod/direct    0/rm32/EAX    .           .             .           .           .               0xff/imm32        # bitwise and of EAX
     3d/compare-EAX-and  0x29/imm32/close-paren
     0f 84/jump-if-equal  $parse-effective-address:end/disp32
+    # if (*word->start == '-') goto displacement
+    3d/compare-EAX-and  0x2d/imm32/minus
+    0f 84/jump-if-equal  $parse-effective-address:displacement/disp32
     # if (*word->start != '+') goto error2
 $parse-effective-address:check-for-index:
     # ++word->start to skip '+'
@@ -1938,6 +1942,68 @@ test-parse-effective-address-base-displacement:
     5d/pop-to-EBP
     c3/return
 
+test-parse-effective-address-base-negative-displacement:
+    # . prolog
+    55/push-EBP
+    89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
+    # var slice/ECX = "*(esi-3)"
+    b8/copy-to-EAX  "*(esi-3)"/imm32
+    8b/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # copy *EAX to ECX
+    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/EAX  1/index/ECX   .           1/r32/ECX   4/disp8         .                 # copy EAX+ECX+4 to ECX
+    05/add-to-EAX  4/imm32
+    # . ECX = {EAX, ECX}
+    51/push-ECX
+    50/push-EAX
+    89/copy                         3/mod/direct    1/rm32/ECX    .           .             .           4/r32/ESP   .               .                 # copy ESP to ECX
+    # EAX, ECX, EDX, EBX = parse-effective-address(slice)
+    # . . push args
+    51/push-ECX
+    # . . call
+    e8/call  parse-effective-address/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # slice clobbered beyond this point
+    # check-ints-equal(EAX, 6, msg)
+    # . . push args
+    68/push  "F - test-parse-effective-address-base-negative-displacement/base"/imm32
+    68/push  6/imm32/ESI
+    50/push-EAX
+    # . . call
+    e8/call  check-ints-equal/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    # check-ints-equal(ECX, 4, msg)
+    # . . push args
+    68/push  "F - test-parse-effective-address-base-negative-displacement/index"/imm32
+    68/push  4/imm32/none
+    51/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
+    # check-ints-equal(EDX, 0, msg)
+    # . . push args
+    68/push  "F - test-parse-effective-address-base-negative-displacement/scale"/imm32
+    68/push  0/imm32/none
+    52/push-EDX
+    # . . call
+    e8/call  check-ints-equal/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    # check-ints-equal(EBX, -3, msg)
+    # . . push args
+    68/push  "F - test-parse-effective-address-base-negative-displacement/displacement"/imm32
+    68/push  -3/imm32
+    53/push-EBX
+    # . . 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
+
 test-parse-effective-address-base-index:
     # . prolog
     55/push-EBP