diff options
-rw-r--r-- | subx/063hex.subx (renamed from subx/071hex.subx) | 27 | ||||
-rw-r--r-- | subx/064print-byte.subx (renamed from subx/063print-byte.subx) | 46 | ||||
-rw-r--r-- | subx/065write-buffered.subx (renamed from subx/064write-buffered.subx) | 0 | ||||
-rw-r--r-- | subx/066error-byte.subx (renamed from subx/065error-byte.subx) | 0 | ||||
-rw-r--r-- | subx/067allocate.subx (renamed from subx/066allocate.subx) | 0 | ||||
-rw-r--r-- | subx/068new-stream.subx (renamed from subx/067new-stream.subx) | 0 | ||||
-rw-r--r-- | subx/069read-line.subx (renamed from subx/068read-line.subx) | 0 | ||||
-rw-r--r-- | subx/070slice.subx (renamed from subx/069slice.subx) | 0 | ||||
-rw-r--r-- | subx/071next-token.subx (renamed from subx/070next-token.subx) | 0 | ||||
-rwxr-xr-x | subx/apps/crenshaw2-1 | bin | 14191 -> 14144 bytes | |||
-rwxr-xr-x | subx/apps/crenshaw2-1b | bin | 14750 -> 14703 bytes | |||
-rwxr-xr-x | subx/apps/factorial | bin | 13109 -> 13062 bytes | |||
-rwxr-xr-x | subx/apps/handle | bin | 13902 -> 13855 bytes | |||
-rwxr-xr-x | subx/apps/hex | bin | 17170 -> 17123 bytes | |||
-rw-r--r-- | subx/apps/hex.subx | 12 |
15 files changed, 28 insertions, 57 deletions
diff --git a/subx/071hex.subx b/subx/063hex.subx index 754e674e..6c36c74b 100644 --- a/subx/071hex.subx +++ b/subx/063hex.subx @@ -309,14 +309,11 @@ $parse-hex-int:loop: # if (curr >= in->end) break 39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . . # compare ECX with EDX 7d/jump-if-greater-or-equal $parse-hex-int:negate/disp8 - # EAX = parse-hex-digit(*curr) - # . . push args + # EAX = from-hex-char(*curr) + # . . copy arg to EAX 8a/copy-byte 0/mod/indirect 1/rm32/ECX . . . 0/r32/AL . . # copy byte at *ECX to AL - 50/push-EAX # . . call - e8/call parse-hex-digit/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + e8/call from-hex-char/disp32 # result = result * 16 + EAX c1/shift 4/subop/left 3/mod/direct 3/rm32/EBX . . . . . 4/imm8 # shift EBX left by 4 bits 01/add 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . . # add EAX to EBX @@ -673,18 +670,30 @@ test-hex-above-f: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP c3/return -parse-hex-digit: # in/EAX : byte -> out/EAX : num +from-hex-char: # in/EAX : byte -> out/EAX : num # no error checking; accepts argument in EAX # if EAX <= '9' return EAX - '0' 3d/compare-EAX 0x39/imm32/9 - 7f/jump-if-greater $parse-hex-digit:else/disp8 + 7f/jump-if-greater $from-hex-char:else/disp8 2d/subtract-from-EAX 0x30/imm32/0 c3/return -$parse-hex-digit:else: +$from-hex-char:else: # otherwise return EAX - 'a' + 10 2d/subtract-from-EAX 0x57/imm32/a-10 c3/return +to-hex-char: # in/EAX : nibble -> out/EAX : byte + # no error checking; accepts argument in EAX + # if EAX <= 9 return EAX + '0' + 3d/compare-EAX 0x9/imm32/9 + 7f/jump-if-greater $to-hex-char:else/disp8 + 05/add-to-EAX 0x30/imm32/0 + c3/return +$to-hex-char:else: + # otherwise return EAX + 'a' - 10 + 05/add-to-EAX 0x57/imm32/a-10 + c3/return + == data _test-slice-empty: diff --git a/subx/063print-byte.subx b/subx/064print-byte.subx index 8bd9fbfc..dacc78d9 100644 --- a/subx/063print-byte.subx +++ b/subx/064print-byte.subx @@ -21,13 +21,8 @@ print-byte: # f : (address buffered-file), n : int -> <void> # AL = convert upper nibble to hex 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 0xc/disp8 . # copy *(EBP+12) to EAX c1/shift 5/subop/logic-right 3/mod/direct 0/rm32/EAX . . . . . 4/imm8 # shift EAX right by 4 bits, while padding zeroes - # . hex-char(AL) - # . . push args - 50/push-EAX - # . . call - e8/call hex-char/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . AL = to-hex-char(AL) + e8/call to-hex-char/disp32 # write-byte(f, AL) # . . push args 50/push-EAX @@ -39,13 +34,8 @@ print-byte: # f : (address buffered-file), n : int -> <void> # AL = convert lower nibble to hex 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 0xc/disp8 . # copy *(EBP+12) to EAX 25/and-EAX 0xf/imm32 - # . hex-char(AL) - # . . push args - 50/push-EAX - # . . call - e8/call hex-char/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . AL = to-hex-char(AL) + e8/call to-hex-char/disp32 # write-byte(f, AL) # . . push args 50/push-EAX @@ -63,34 +53,6 @@ $print-byte:end: 5d/pop-to-EBP c3/return -# extract lowest 4 bits and convert to 8-byte ascii -# return 0xffffffff if more than 4 bits are set -hex-char: # n : int -> char_or_error/EAX - # . prolog - 55/push-EBP - 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP - # EAX = n - 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 8/disp8 . # copy *(EBP+8) to EAX - # if it's <= 9 add '0' to it - 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0x9/imm32 # compare EAX - 7f/jump-if-greater $hex-char:check2/disp8 - 05/add-to-EAX 0x30/imm32/'0' - eb/jump $hex-char:end/disp8 -$hex-char:check2: - # else if it's <= 15 add ('a' - 10) to it - 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xf/imm32 # compare EAX - 7f/jump-if-greater $hex-char:error/disp8 - 05/add-to-EAX 0x57/imm32 # 'a' - 10 - eb/jump $hex-char:end/disp8 -$hex-char:error: - # otherwise return 0xffffffff - b8/copy-to-EAX 0xffffffff/imm32 -$hex-char:end: - # . epilog - 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP - 5d/pop-to-EBP - c3/return - test-print-byte: # - check that print-byte prints the hex textual representation # setup diff --git a/subx/064write-buffered.subx b/subx/065write-buffered.subx index 9ae08b21..9ae08b21 100644 --- a/subx/064write-buffered.subx +++ b/subx/065write-buffered.subx diff --git a/subx/065error-byte.subx b/subx/066error-byte.subx index 5f9a4ada..5f9a4ada 100644 --- a/subx/065error-byte.subx +++ b/subx/066error-byte.subx diff --git a/subx/066allocate.subx b/subx/067allocate.subx index 37b01d21..37b01d21 100644 --- a/subx/066allocate.subx +++ b/subx/067allocate.subx diff --git a/subx/067new-stream.subx b/subx/068new-stream.subx index 2020229d..2020229d 100644 --- a/subx/067new-stream.subx +++ b/subx/068new-stream.subx diff --git a/subx/068read-line.subx b/subx/069read-line.subx index 961fc521..961fc521 100644 --- a/subx/068read-line.subx +++ b/subx/069read-line.subx diff --git a/subx/069slice.subx b/subx/070slice.subx index 7be920ec..7be920ec 100644 --- a/subx/069slice.subx +++ b/subx/070slice.subx diff --git a/subx/070next-token.subx b/subx/071next-token.subx index 539caf95..539caf95 100644 --- a/subx/070next-token.subx +++ b/subx/071next-token.subx diff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1 index 1d314e4e..8010cdac 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 b18e13a1..3cdb555e 100755 --- a/subx/apps/crenshaw2-1b +++ b/subx/apps/crenshaw2-1b Binary files differdiff --git a/subx/apps/factorial b/subx/apps/factorial index dc2b81ad..4489b6ad 100755 --- a/subx/apps/factorial +++ b/subx/apps/factorial Binary files differdiff --git a/subx/apps/handle b/subx/apps/handle index 6a6d12f9..65b94caa 100755 --- a/subx/apps/handle +++ b/subx/apps/handle Binary files differdiff --git a/subx/apps/hex b/subx/apps/hex index 95f1956c..66aa0dce 100755 --- a/subx/apps/hex +++ b/subx/apps/hex Binary files differdiff --git a/subx/apps/hex.subx b/subx/apps/hex.subx index 0d2caefe..52e910f8 100644 --- a/subx/apps/hex.subx +++ b/subx/apps/hex.subx @@ -131,10 +131,10 @@ convert-next-octet: # in : (address buffered-file), err : (address buffered-fil # pseudocode: # EAX = scan-next-byte(in, err, ed) # if (EAX == 0xffffffff) return - # ECX = parse-hex-digit(EAX) + # ECX = from-hex-char(EAX) # EAX = scan-next-byte(in, err, ed) # if (EAX == 0xffffffff) error("partial byte found.") - # EAX = parse-hex-digit(EAX) + # EAX = from-hex-char(EAX) # EAX = (ECX << 4) | EAX # return # @@ -155,8 +155,8 @@ convert-next-octet: # in : (address buffered-file), err : (address buffered-fil # if (EAX == 0xffffffff) return 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xffffffff/imm32 # compare EAX 74/jump-if-equal $convert-next-octet:end/disp8 - # EAX = parse-hex-digit(EAX) - e8/call parse-hex-digit/disp32 + # EAX = from-hex-char(EAX) + e8/call from-hex-char/disp32 # ECX = EAX 89/copy 3/mod/direct 1/rm32/ECX . . . 0/r32/EAX . . # copy EAX to ECX # EAX = scan-next-byte(in, err, ed) @@ -180,8 +180,8 @@ convert-next-octet: # in : (address buffered-file), err : (address buffered-fil # . . call e8/call error-byte/disp32 # never returns $convert-next-octet:convert: - # EAX = parse-hex-digit(EAX) - e8/call parse-hex-digit/disp32 + # EAX = from-hex-char(EAX) + e8/call from-hex-char/disp32 # EAX = (ECX << 4) | EAX # . ECX <<= 4 c1/shift 4/subop/left 3/mod/direct 1/rm32/ECX . . . . . 4/imm8 # shift ECX left by 4 bits |