From 0ad068dd1da3d463f71c4b63028278767d62af9c Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 1 Feb 2019 23:49:41 -0800 Subject: 4945 --- subx/063hex.subx | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ subx/apps/crenshaw2-1 | Bin 15310 -> 15531 bytes subx/apps/crenshaw2-1b | Bin 15869 -> 16090 bytes subx/apps/factorial | Bin 14228 -> 14449 bytes subx/apps/handle | Bin 15021 -> 15242 bytes subx/apps/hex | Bin 18289 -> 18510 bytes subx/apps/pack | Bin 16082 -> 16303 bytes 7 files changed, 70 insertions(+) (limited to 'subx') diff --git a/subx/063hex.subx b/subx/063hex.subx index 7d753f92..6ba2ef7e 100644 --- a/subx/063hex.subx +++ b/subx/063hex.subx @@ -31,6 +31,14 @@ is-hex-int?: # in : (address slice) -> EAX : boolean b8/copy-to-EAX 0/imm32/false 39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . . # compare ECX with EDX 7d/jump-if-greater-or-equal $is-hex-int?:end/disp8 + # skip past leading '-' + # . if (*curr == '-') ++curr + 31/xor 3/mod/direct 3/rm32/EBX . . . 3/r32/EBX . . # clear EBX + 8a/copy-byte 0/mod/indirect 1/rm32/ECX . . . 3/r32/BL . . # copy byte at *ECX to BL + 81 7/subop/compare 3/mod/direct 3/rm32/EBX . . . . . 0x2d/imm32/- # compare EBX + 75/jump-if-not-equal $is-hex-int?:initial-0/disp8 + # . ++curr + 41/increment-ECX # skip past leading '0x' $is-hex-int?:initial-0: # . if (*curr != '0') jump to loop @@ -257,6 +265,64 @@ test-is-hex-int-handles-0x-prefix: 5d/pop-to-EBP c3/return +test-is-hex-int-handles-negative: + # . prolog + 55/push-EBP + 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP + # var slice/ECX = "-34a" + 68/push _test-slice-hex-int-letters-end/imm32 + 68/push _test-slice-hex-int-letters-negative/imm32 + 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX + # EAX = is-hex-int?(slice) + # . . push args + 51/push-ECX + # . . call + e8/call is-hex-int?/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # check-ints-equal(EAX, 1, msg) + # . . push args + 68/push "F - test-is-hex-int-handles-negative"/imm32 + 68/push 1/imm32/true + 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 + # . epilog + 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP + 5d/pop-to-EBP + c3/return + +test-is-hex-int-handles-negative-0x-prefix: + # . prolog + 55/push-EBP + 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP + # var slice/ECX = "-0x3a" + 68/push _test-slice-hex-int-with-0x-prefix-end/imm32 + 68/push _test-slice-hex-int-with-0x-prefix-negative/imm32 + 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX + # EAX = is-hex-int?(slice) + # . . push args + 51/push-ECX + # . . call + e8/call is-hex-int?/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # check-ints-equal(EAX, 1, msg) + # . . push args + 68/push "F - test-is-hex-int-handles-negative-0x-prefix"/imm32 + 68/push 1/imm32/true + 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 + # . epilog + 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP + 5d/pop-to-EBP + c3/return + parse-hex-int: # in : (address slice) -> result/EAX # . prolog 55/push-EBP @@ -704,6 +770,8 @@ _test-slice-hex-int: 33/3 34/4 _test-slice-hex-int-end: +_test-slice-hex-int-letters-negative: + 2d/- _test-slice-hex-int-letters: 33/3 34/4 61/a _test-slice-hex-int-letters-end: @@ -720,6 +788,8 @@ _test-slice-digits-and-char: 33/3 34/4 71/q _test-slice-digits-and-char-end: +_test-slice-hex-int-with-0x-prefix-negative: + 2d/- _test-slice-hex-int-with-0x-prefix: 30/0 78/x 33/3 34/4 _test-slice-hex-int-with-0x-prefix-end: diff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1 index c21bdb6b..3e694fa1 100755 Binary files a/subx/apps/crenshaw2-1 and b/subx/apps/crenshaw2-1 differ diff --git a/subx/apps/crenshaw2-1b b/subx/apps/crenshaw2-1b index b8408351..6e26f2c6 100755 Binary files a/subx/apps/crenshaw2-1b and b/subx/apps/crenshaw2-1b differ diff --git a/subx/apps/factorial b/subx/apps/factorial index 83af72ba..52b8787d 100755 Binary files a/subx/apps/factorial and b/subx/apps/factorial differ diff --git a/subx/apps/handle b/subx/apps/handle index 3d3e555d..60337c7e 100755 Binary files a/subx/apps/handle and b/subx/apps/handle differ diff --git a/subx/apps/hex b/subx/apps/hex index c7460132..56f7471b 100755 Binary files a/subx/apps/hex and b/subx/apps/hex differ diff --git a/subx/apps/pack b/subx/apps/pack index a12b6458..162559e0 100755 Binary files a/subx/apps/pack and b/subx/apps/pack differ -- cgit 1.4.1-2-gfad0