diff options
Diffstat (limited to 'subx')
-rw-r--r-- | subx/apps/hex | bin | 10579 -> 11142 bytes | |||
-rw-r--r-- | subx/apps/hex.subx | 184 |
2 files changed, 184 insertions, 0 deletions
diff --git a/subx/apps/hex b/subx/apps/hex index 72321585..aaca7324 100644 --- a/subx/apps/hex +++ b/subx/apps/hex Binary files differdiff --git a/subx/apps/hex.subx b/subx/apps/hex.subx index 3cb1a005..9f24e349 100644 --- a/subx/apps/hex.subx +++ b/subx/apps/hex.subx @@ -258,6 +258,190 @@ $test-convert-next-hex-byte:end: 5d/pop-to-EBP c3/return +test-convert-next-hex-byte-handles-eof: + # - check that eof returns the sentinel octet + # This test uses exit-descriptors. Use EBP for setting up local variables. + 55/push-EBP + 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP + # clear all streams + # . clear-stream(_test-stream) + # . . push args + 68/push _test-stream/imm32 + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . clear-stream(_test-buffered-file+4) + # . . push args + b8/copy-to-EAX _test-buffered-file/imm32 + 05/add-to-EAX 4/imm32 + 50/push-EAX + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . clear-stream(_test-error-stream) + # . . push args + 68/push _test-error-stream/imm32 + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . clear-stream(_test-error-buffered-file+4) + # . . push args + b8/copy-to-EAX _test-error-buffered-file/imm32 + 05/add-to-EAX 4/imm32 + 50/push-EAX + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # don't initialize '_test-stream' + # initialize exit-descriptor 'ed' for the call to 'convert-next-hex-byte' below + # . var ed/ECX : exit-descriptor + 81 5/subop/subtract 3/mod/direct 4/rm32/ESP . . . . . 8/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 + # . tailor-exit-descriptor(ed, 12) + # . . push args + 68/push 0xc/imm32/nbytes-of-args-for-convert-next-hex-byte + 51/push-ECX/ed + # . . call + e8/call tailor-exit-descriptor/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # EAX = convert-next-hex-byte(_test-buffered-file, _test-error-buffered-file, ed) + # . . push args + 51/push-ECX/ed + 68/push _test-error-buffered-file/imm32 + 68/push _test-buffered-file/imm32 + # . . call + e8/call convert-next-hex-byte/disp32 + # registers except ESP may be clobbered at this point + # pop args to convert-next-hex-bytes + # . . discard first 2 args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . . restore ed + 59/pop-to-ECX + # check that convert-next-hex-byte didn't abort + # . check-ints-equal(ed->value, 0, msg) + # . . push args + 68/push "F - test-convert-next-hex-byte: unexpected abort"/imm32 + 68/push 0/imm32 + # . . push ed->value + ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 . # push *(ECX+4) + # . . call + e8/call check-ints-equal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP + # return if abort + 81 7/subop/compare 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 0/imm32 # compare *(ECX+4) + 75/jump-if-not-equal $test-convert-next-hex-byte-handles-eof:end/disp8 + # check-ints-equal(EAX, 0xffffffff, msg) + # . . push args + 68/push "F - test-convert-next-hex-byte-handles-eof"/imm32 + 68/push 0xffffffff/imm32/eof + 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 +$test-convert-next-hex-byte-handles-eof:end: + # . epilog + # don't restore ESP from EBP; manually reclaim locals + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + 5d/pop-to-EBP + c3/return + +test-convert-next-hex-byte-aborts-on-single-hex-byte: + # - check that a single unaccompanied hex byte aborts + # This test uses exit-descriptors. Use EBP for setting up local variables. + 55/push-EBP + 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP + # clear all streams + # . clear-stream(_test-stream) + # . . push args + 68/push _test-stream/imm32 + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . clear-stream(_test-buffered-file+4) + # . . push args + b8/copy-to-EAX _test-buffered-file/imm32 + 05/add-to-EAX 4/imm32 + 50/push-EAX + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . clear-stream(_test-error-stream) + # . . push args + 68/push _test-error-stream/imm32 + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . clear-stream(_test-error-buffered-file+4) + # . . push args + b8/copy-to-EAX _test-error-buffered-file/imm32 + 05/add-to-EAX 4/imm32 + 50/push-EAX + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # initialize '_test-stream' to "a" + # . write(_test-stream, "a") + # . . push args + 68/push "a"/imm32 + 68/push _test-stream/imm32 + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # initialize exit-descriptor 'ed' for the call to 'convert-next-hex-byte' below + # . var ed/ECX : exit-descriptor + 81 5/subop/subtract 3/mod/direct 4/rm32/ESP . . . . . 8/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 + # . tailor-exit-descriptor(ed, 12) + # . . push args + 68/push 0xc/imm32/nbytes-of-args-for-convert-next-hex-byte + 51/push-ECX/ed + # . . call + e8/call tailor-exit-descriptor/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # EAX = convert-next-hex-byte(_test-buffered-file, _test-error-buffered-file, ed) + # . . push args + 51/push-ECX/ed + 68/push _test-error-buffered-file/imm32 + 68/push _test-buffered-file/imm32 + # . . call + e8/call convert-next-hex-byte/disp32 + # registers except ESP may be clobbered at this point + # pop args to convert-next-hex-bytes + # . . discard first 2 args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . . restore ed + 59/pop-to-ECX + # check that convert-next-hex-byte aborted + # . check-ints-equal(ed->value, 2, msg) + # . . push args + 68/push "F - test-convert-next-hex-byte-aborts-on-single-hex-byte: unexpected abort"/imm32 + 68/push 2/imm32 + # . . push ed->value + ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 . # push *(ECX+4) + # . . call + e8/call check-ints-equal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP +$test-convert-next-hex-byte-aborts-on-single-hex-byte:end: + # . epilog + # don't restore ESP from EBP; manually reclaim locals + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + 5d/pop-to-EBP + c3/return + # read whitespace until a hex byte, and return it # return 0xffffffff if file ends without finding a hex byte # on '#' skip all bytes until newline |