From 05dabd816a8ead6ff0e949cc16bf30140811bad6 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 29 Jun 2020 17:58:01 -0700 Subject: 6594 - start standardizing the meaning of 'print' --- 066print-int.subx | 386 ----------------------------------- 066write-int-hex.subx | 386 +++++++++++++++++++++++++++++++++++ 068error-byte.subx | 4 +- 078emit-hex.subx | 4 +- 091write-int.subx | 2 +- apps/assort | Bin 44392 -> 44396 bytes apps/braces | Bin 46255 -> 46259 bytes apps/calls | Bin 50902 -> 50906 bytes apps/crenshaw2-1 | Bin 43733 -> 43737 bytes apps/crenshaw2-1b | Bin 44280 -> 44284 bytes apps/dquotes | Bin 48014 -> 48018 bytes apps/factorial | Bin 42836 -> 42840 bytes apps/hex | Bin 46572 -> 46576 bytes apps/mu | Bin 341134 -> 341138 bytes apps/pack | Bin 56971 -> 56975 bytes apps/sigils | Bin 58624 -> 58628 bytes apps/survey | Bin 54324 -> 54328 bytes apps/tests | Bin 43164 -> 43168 bytes html/066print-int.subx.html | 434 ---------------------------------------- html/066write-int-hex.subx.html | 434 ++++++++++++++++++++++++++++++++++++++++ 20 files changed, 825 insertions(+), 825 deletions(-) delete mode 100644 066print-int.subx create mode 100644 066write-int-hex.subx delete mode 100644 html/066print-int.subx.html create mode 100644 html/066write-int-hex.subx.html diff --git a/066print-int.subx b/066print-int.subx deleted file mode 100644 index cc604ce8..00000000 --- a/066print-int.subx +++ /dev/null @@ -1,386 +0,0 @@ -# Print the (hex) textual representation of numbers. - -== code -# instruction effective address register displacement immediate -# . 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 - -# convert the lowest nibble of eax to ascii and return it in the lowest byte of eax -to-hex-char: # in/eax: int -> out/eax: int - # no error checking; accepts argument in eax - # if (eax <= 9) return eax + '0' - 3d/compare-eax-with 0x9/imm32/9 - 7f/jump-if-> $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 - -append-byte-hex: # f: (addr stream byte), n: int - # . prologue - 55/push-ebp - 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp - # . save registers - 50/push-eax - # 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 - 25/and-eax 0xf/imm32 - # . AL = to-hex-char(AL) - e8/call to-hex-char/disp32 - # append-byte(f, AL) - # . . push args - 50/push-eax - ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) - # . . call - e8/call append-byte/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # 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 - # . AL = to-hex-char(AL) - e8/call to-hex-char/disp32 - # append-byte(f, AL) - # . . push args - 50/push-eax - ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) - # . . call - e8/call append-byte/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp -$append-byte-hex:end: - # . restore registers - 58/pop-to-eax - # . epilogue - 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp - 5d/pop-to-ebp - c3/return - -test-append-byte-hex: - # - check that append-byte-hex adds the hex textual representation - # setup - # . 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 - # append-byte-hex(_test-stream, 0xa) # exercises digit, non-digit as well as leading zero - # . . push args - 68/push 0xa/imm32 - 68/push _test-stream/imm32 - # . . call - e8/call append-byte-hex/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # check-stream-equal(_test-stream, "0a", msg) - # . . push args - 68/push "F - test-append-byte-hex"/imm32 - 68/push "0a"/imm32 - 68/push _test-stream/imm32 - # . . call - e8/call check-stream-equal/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp - # . end - c3/return - -# print the hex representation for the lowest byte of a number -print-byte-buffered: # f: (addr buffered-file), n: int - # . prologue - 55/push-ebp - 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp - # . save registers - 50/push-eax - # 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 - 25/and-eax 0xf/imm32 - # . AL = to-hex-char(AL) - e8/call to-hex-char/disp32 - # write-byte-buffered(f, AL) - # . . push args - 50/push-eax - ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) - # . . call - e8/call write-byte-buffered/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # 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 - # . AL = to-hex-char(AL) - e8/call to-hex-char/disp32 - # write-byte-buffered(f, AL) - # . . push args - 50/push-eax - ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) - # . . call - e8/call write-byte-buffered/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp -$print-byte-buffered:end: - # . restore registers - 58/pop-to-eax - # . epilogue - 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp - 5d/pop-to-ebp - c3/return - -test-print-byte-buffered: - # - check that print-byte-buffered prints the hex textual representation - # setup - # . 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->buffer) - # . . push args - 68/push $_test-buffered-file->buffer/imm32 - # . . call - e8/call clear-stream/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp - # print-byte-buffered(_test-buffered-file, 0xa) # exercises digit, non-digit as well as leading zero - # . . push args - 68/push 0xa/imm32 - 68/push _test-buffered-file/imm32 - # . . call - e8/call print-byte-buffered/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # flush(_test-buffered-file) - # . . push args - 68/push _test-buffered-file/imm32 - # . . call - e8/call flush/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp - # check-stream-equal(_test-stream, "0a", msg) - # . . push args - 68/push "F - test-print-byte-buffered"/imm32 - 68/push "0a"/imm32 - 68/push _test-stream/imm32 - # . . call - e8/call check-stream-equal/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp - # . end - c3/return - -print-int32: # f: (addr stream byte), n: int - # pseudocode: - # write(f, "0x") - # ecx = 28 - # while true - # if (ecx < 0) break - # eax = n >> ecx - # eax = eax & 0xf - # append-byte(f, AL) - # ecx -= 4 - # - # . prologue - 55/push-ebp - 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp - # . save registers - 50/push-eax - 51/push-ecx - # ecx = 28 - b9/copy-to-ecx 0x1c/imm32 -$print-int32:print-hex-prefix: - # write(f, "0x") - # . . push args - 68/push "0x"/imm32 - ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) - # . . call - e8/call write/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp -$print-int32:loop: - # if (ecx < 0) break - 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0/imm32 # compare ecx - 7c/jump-if-< $print-int32:end/disp8 - # eax = n >> ecx - 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 . # copy *(ebp+12) to eax - d3/>>ecx 5/subop/pad-zeroes 3/mod/direct 0/rm32/eax . . . . . . # shift eax right by ecx bits, padding zeroes - # eax = to-hex-char(AL) - 25/and-eax 0xf/imm32 - e8/call to-hex-char/disp32 - # append-byte(f, AL) - # . . push args - 50/push-eax - ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) - # . . call - e8/call append-byte/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # ecx -= 4 - 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32 # subtract from ecx - eb/jump $print-int32:loop/disp8 -$print-int32:end: - # . restore registers - 59/pop-to-ecx - 58/pop-to-eax - # . epilogue - 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp - 5d/pop-to-ebp - c3/return - -test-print-int32: - # - check that print-int32 prints the hex textual representation - # setup - # . 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 - # print-int32(_test-stream, 0x8899aa) - # . . push args - 68/push 0x8899aa/imm32 - 68/push _test-stream/imm32 - # . . call - e8/call print-int32/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # check-stream-equal(_test-stream, "0x008899aa", msg) - # . . push args - 68/push "F - test-print-int32"/imm32 - 68/push "0x008899aa"/imm32 - 68/push _test-stream/imm32 - # . . call - e8/call check-stream-equal/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp - # . end - c3/return - -print-int32-buffered: # f: (addr buffered-file), n: int - # pseudocode: - # write-buffered(f, "0x") - # ecx = 28 - # while true - # if (ecx < 0) break - # eax = n >> ecx - # eax = eax & 0xf - # write-byte-buffered(f, AL) - # ecx -= 4 - # - # . prologue - 55/push-ebp - 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp - # . save registers - 50/push-eax - 51/push-ecx - # ecx = 28 - b9/copy-to-ecx 0x1c/imm32 -$print-int32-buffered:print-hex-prefix: - # write-buffered(f, "0x") - # . . push args - 68/push "0x"/imm32 - ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) - # . . call - e8/call write-buffered/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp -$print-int32-buffered:loop: - # if (ecx < 0) break - 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0/imm32 # compare ecx - 7c/jump-if-< $print-int32-buffered:end/disp8 - # eax = n >> ecx - 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 . # copy *(ebp+12) to eax - d3/>>ecx 5/subop/pad-zeroes 3/mod/direct 0/rm32/eax . . . . . . # shift eax right by ecx bits, padding zeroes - # eax = to-hex-char(AL) - 25/and-eax 0xf/imm32 - e8/call to-hex-char/disp32 - # write-byte-buffered(f, AL) - # . . push args - 50/push-eax - ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) - # . . call - e8/call write-byte-buffered/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # ecx -= 4 - 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32 # subtract from ecx - eb/jump $print-int32-buffered:loop/disp8 -$print-int32-buffered:end: - # . restore registers - 59/pop-to-ecx - 58/pop-to-eax - # . epilogue - 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp - 5d/pop-to-ebp - c3/return - -test-print-int32-buffered: - # - check that print-int32-buffered prints the hex textual representation - # setup - # . 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->buffer) - # . . push args - 68/push $_test-buffered-file->buffer/imm32 - # . . call - e8/call clear-stream/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp - # print-int32-buffered(_test-buffered-file, 0x8899aa) - # . . push args - 68/push 0x8899aa/imm32 - 68/push _test-buffered-file/imm32 - # . . call - e8/call print-int32-buffered/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # flush(_test-buffered-file) - # . . push args - 68/push _test-buffered-file/imm32 - # . . call - e8/call flush/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -#? # dump line {{{ -#? # . write-stream(2/stderr, line) -#? # . . push args -#? 68/push _test-stream/imm32 -#? 68/push 2/imm32/stderr -#? # . . call -#? e8/call write-stream/disp32 -#? # . . discard args -#? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp -#? # . write(2/stderr, "$\n") -#? # . . push args -#? 68/push "$\n"/imm32 -#? 68/push 2/imm32/stderr -#? # . . call -#? e8/call write/disp32 -#? # . . discard args -#? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp -#? # }}} - # check-stream-equal(_test-stream, "0x008899aa", msg) - # . . push args - 68/push "F - test-print-int32-buffered"/imm32 - 68/push "0x008899aa"/imm32 - 68/push _test-stream/imm32 - # . . call - e8/call check-stream-equal/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp - # . end - c3/return - -# . . vim:nowrap:textwidth=0 diff --git a/066write-int-hex.subx b/066write-int-hex.subx new file mode 100644 index 00000000..6746891e --- /dev/null +++ b/066write-int-hex.subx @@ -0,0 +1,386 @@ +# Write out the (hex) textual representation of numbers. + +== code +# instruction effective address register displacement immediate +# . 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 + +# convert the lowest nibble of eax to ascii and return it in the lowest byte of eax +to-hex-char: # in/eax: int -> out/eax: int + # no error checking; accepts argument in eax + # if (eax <= 9) return eax + '0' + 3d/compare-eax-with 0x9/imm32/9 + 7f/jump-if-> $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 + +append-byte-hex: # f: (addr stream byte), n: int + # . prologue + 55/push-ebp + 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp + # . save registers + 50/push-eax + # 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 + 25/and-eax 0xf/imm32 + # . AL = to-hex-char(AL) + e8/call to-hex-char/disp32 + # append-byte(f, AL) + # . . push args + 50/push-eax + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) + # . . call + e8/call append-byte/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # 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 + # . AL = to-hex-char(AL) + e8/call to-hex-char/disp32 + # append-byte(f, AL) + # . . push args + 50/push-eax + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) + # . . call + e8/call append-byte/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +$append-byte-hex:end: + # . restore registers + 58/pop-to-eax + # . epilogue + 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp + 5d/pop-to-ebp + c3/return + +test-append-byte-hex: + # - check that append-byte-hex adds the hex textual representation + # setup + # . 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 + # append-byte-hex(_test-stream, 0xa) # exercises digit, non-digit as well as leading zero + # . . push args + 68/push 0xa/imm32 + 68/push _test-stream/imm32 + # . . call + e8/call append-byte-hex/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # check-stream-equal(_test-stream, "0a", msg) + # . . push args + 68/push "F - test-append-byte-hex"/imm32 + 68/push "0a"/imm32 + 68/push _test-stream/imm32 + # . . call + e8/call check-stream-equal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp + # . end + c3/return + +# print the hex representation for the lowest byte of a number +write-byte-hex-buffered: # f: (addr buffered-file), n: int + # . prologue + 55/push-ebp + 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp + # . save registers + 50/push-eax + # 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 + 25/and-eax 0xf/imm32 + # . AL = to-hex-char(AL) + e8/call to-hex-char/disp32 + # write-byte-buffered(f, AL) + # . . push args + 50/push-eax + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) + # . . call + e8/call write-byte-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # 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 + # . AL = to-hex-char(AL) + e8/call to-hex-char/disp32 + # write-byte-buffered(f, AL) + # . . push args + 50/push-eax + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) + # . . call + e8/call write-byte-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +$write-byte-hex-buffered:end: + # . restore registers + 58/pop-to-eax + # . epilogue + 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp + 5d/pop-to-ebp + c3/return + +test-write-byte-hex-buffered: + # - check that write-byte-hex-buffered prints the hex textual representation + # setup + # . 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->buffer) + # . . push args + 68/push $_test-buffered-file->buffer/imm32 + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp + # write-byte-hex-buffered(_test-buffered-file, 0xa) # exercises digit, non-digit as well as leading zero + # . . push args + 68/push 0xa/imm32 + 68/push _test-buffered-file/imm32 + # . . call + e8/call write-byte-hex-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # flush(_test-buffered-file) + # . . push args + 68/push _test-buffered-file/imm32 + # . . call + e8/call flush/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp + # check-stream-equal(_test-stream, "0a", msg) + # . . push args + 68/push "F - test-write-byte-hex-buffered"/imm32 + 68/push "0a"/imm32 + 68/push _test-stream/imm32 + # . . call + e8/call check-stream-equal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp + # . end + c3/return + +print-int32: # f: (addr stream byte), n: int + # pseudocode: + # write(f, "0x") + # ecx = 28 + # while true + # if (ecx < 0) break + # eax = n >> ecx + # eax = eax & 0xf + # append-byte(f, AL) + # ecx -= 4 + # + # . prologue + 55/push-ebp + 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp + # . save registers + 50/push-eax + 51/push-ecx + # ecx = 28 + b9/copy-to-ecx 0x1c/imm32 +$print-int32:print-hex-prefix: + # write(f, "0x") + # . . push args + 68/push "0x"/imm32 + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +$print-int32:loop: + # if (ecx < 0) break + 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0/imm32 # compare ecx + 7c/jump-if-< $print-int32:end/disp8 + # eax = n >> ecx + 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 . # copy *(ebp+12) to eax + d3/>>ecx 5/subop/pad-zeroes 3/mod/direct 0/rm32/eax . . . . . . # shift eax right by ecx bits, padding zeroes + # eax = to-hex-char(AL) + 25/and-eax 0xf/imm32 + e8/call to-hex-char/disp32 + # append-byte(f, AL) + # . . push args + 50/push-eax + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) + # . . call + e8/call append-byte/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # ecx -= 4 + 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32 # subtract from ecx + eb/jump $print-int32:loop/disp8 +$print-int32:end: + # . restore registers + 59/pop-to-ecx + 58/pop-to-eax + # . epilogue + 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp + 5d/pop-to-ebp + c3/return + +test-print-int32: + # - check that print-int32 prints the hex textual representation + # setup + # . 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 + # print-int32(_test-stream, 0x8899aa) + # . . push args + 68/push 0x8899aa/imm32 + 68/push _test-stream/imm32 + # . . call + e8/call print-int32/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # check-stream-equal(_test-stream, "0x008899aa", msg) + # . . push args + 68/push "F - test-print-int32"/imm32 + 68/push "0x008899aa"/imm32 + 68/push _test-stream/imm32 + # . . call + e8/call check-stream-equal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp + # . end + c3/return + +print-int32-buffered: # f: (addr buffered-file), n: int + # pseudocode: + # write-buffered(f, "0x") + # ecx = 28 + # while true + # if (ecx < 0) break + # eax = n >> ecx + # eax = eax & 0xf + # write-byte-buffered(f, AL) + # ecx -= 4 + # + # . prologue + 55/push-ebp + 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp + # . save registers + 50/push-eax + 51/push-ecx + # ecx = 28 + b9/copy-to-ecx 0x1c/imm32 +$print-int32-buffered:print-hex-prefix: + # write-buffered(f, "0x") + # . . push args + 68/push "0x"/imm32 + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) + # . . call + e8/call write-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +$print-int32-buffered:loop: + # if (ecx < 0) break + 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0/imm32 # compare ecx + 7c/jump-if-< $print-int32-buffered:end/disp8 + # eax = n >> ecx + 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 . # copy *(ebp+12) to eax + d3/>>ecx 5/subop/pad-zeroes 3/mod/direct 0/rm32/eax . . . . . . # shift eax right by ecx bits, padding zeroes + # eax = to-hex-char(AL) + 25/and-eax 0xf/imm32 + e8/call to-hex-char/disp32 + # write-byte-buffered(f, AL) + # . . push args + 50/push-eax + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) + # . . call + e8/call write-byte-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # ecx -= 4 + 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32 # subtract from ecx + eb/jump $print-int32-buffered:loop/disp8 +$print-int32-buffered:end: + # . restore registers + 59/pop-to-ecx + 58/pop-to-eax + # . epilogue + 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp + 5d/pop-to-ebp + c3/return + +test-print-int32-buffered: + # - check that print-int32-buffered prints the hex textual representation + # setup + # . 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->buffer) + # . . push args + 68/push $_test-buffered-file->buffer/imm32 + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp + # print-int32-buffered(_test-buffered-file, 0x8899aa) + # . . push args + 68/push 0x8899aa/imm32 + 68/push _test-buffered-file/imm32 + # . . call + e8/call print-int32-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # flush(_test-buffered-file) + # . . push args + 68/push _test-buffered-file/imm32 + # . . call + e8/call flush/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +#? # dump line {{{ +#? # . write-stream(2/stderr, line) +#? # . . push args +#? 68/push _test-stream/imm32 +#? 68/push 2/imm32/stderr +#? # . . call +#? e8/call write-stream/disp32 +#? # . . discard args +#? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +#? # . write(2/stderr, "$\n") +#? # . . push args +#? 68/push "$\n"/imm32 +#? 68/push 2/imm32/stderr +#? # . . call +#? e8/call write/disp32 +#? # . . discard args +#? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +#? # }}} + # check-stream-equal(_test-stream, "0x008899aa", msg) + # . . push args + 68/push "F - test-print-int32-buffered"/imm32 + 68/push "0x008899aa"/imm32 + 68/push _test-stream/imm32 + # . . call + e8/call check-stream-equal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp + # . end + c3/return + +# . . vim:nowrap:textwidth=0 diff --git a/068error-byte.subx b/068error-byte.subx index 1d7729b5..1ce0a3d6 100644 --- a/068error-byte.subx +++ b/068error-byte.subx @@ -51,12 +51,12 @@ error-byte: # ed: (addr exit-descriptor), out: (addr buffered-file), msg: (addr e8/call write-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # print-byte-buffered(out, byte) + # write-byte-hex-buffered(out, byte) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x14/disp8 . # push *(ebp+20) ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call - e8/call print-byte-buffered/disp32 + e8/call write-byte-hex-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # write-buffered(out, Newline) diff --git a/078emit-hex.subx b/078emit-hex.subx index 075f8e4b..d8869956 100644 --- a/078emit-hex.subx +++ b/078emit-hex.subx @@ -26,12 +26,12 @@ $emit-hex:loop: # if (curr >= width) break 39/compare 3/mod/direct 1/rm32/ecx . . . 2/r32/edx . . # compare ecx with edx 7d/jump-if->= $emit-hex:end/disp8 - # print-byte-buffered(out, ebx) # only BL used + # write-byte-hex-buffered(out, ebx) # only BL used # . . push args 53/push-ebx 57/push-edi # . . call - e8/call print-byte-buffered/disp32 + e8/call write-byte-hex-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # write-byte-buffered(out, ' ') diff --git a/091write-int.subx b/091write-int.subx index 2b5b60a1..97e681c7 100644 --- a/091write-int.subx +++ b/091write-int.subx @@ -1,4 +1,4 @@ -# write-int: add a single int to a stream +# write-int: add (the binary representation of) a single int to a stream == code # instruction effective address register displacement immediate diff --git a/apps/assort b/apps/assort index 7d565a5a..ed5e532e 100755 Binary files a/apps/assort and b/apps/assort differ diff --git a/apps/braces b/apps/braces index b51d7c2a..710fb8a7 100755 Binary files a/apps/braces and b/apps/braces differ diff --git a/apps/calls b/apps/calls index 7c8d6328..18e07c13 100755 Binary files a/apps/calls and b/apps/calls differ diff --git a/apps/crenshaw2-1 b/apps/crenshaw2-1 index 104c787f..3c86c4cc 100755 Binary files a/apps/crenshaw2-1 and b/apps/crenshaw2-1 differ diff --git a/apps/crenshaw2-1b b/apps/crenshaw2-1b index ec4c777c..a9ca75d0 100755 Binary files a/apps/crenshaw2-1b and b/apps/crenshaw2-1b differ diff --git a/apps/dquotes b/apps/dquotes index 3a22d5d7..80b18682 100755 Binary files a/apps/dquotes and b/apps/dquotes differ diff --git a/apps/factorial b/apps/factorial index 34a2c970..4cd0d4e4 100755 Binary files a/apps/factorial and b/apps/factorial differ diff --git a/apps/hex b/apps/hex index 137c479b..e6f9e3f1 100755 Binary files a/apps/hex and b/apps/hex differ diff --git a/apps/mu b/apps/mu index 4710f635..c3144d0a 100755 Binary files a/apps/mu and b/apps/mu differ diff --git a/apps/pack b/apps/pack index bcd5af94..4ff31f99 100755 Binary files a/apps/pack and b/apps/pack differ diff --git a/apps/sigils b/apps/sigils index 48895ab3..798ede8b 100755 Binary files a/apps/sigils and b/apps/sigils differ diff --git a/apps/survey b/apps/survey index 1fdc091f..1aa149e5 100755 Binary files a/apps/survey and b/apps/survey differ diff --git a/apps/tests b/apps/tests index b4c445f2..9db94934 100755 Binary files a/apps/tests and b/apps/tests differ diff --git a/html/066print-int.subx.html b/html/066print-int.subx.html deleted file mode 100644 index dac46129..00000000 --- a/html/066print-int.subx.html +++ /dev/null @@ -1,434 +0,0 @@ - - - - -Mu - 066print-int.subx - - - - - - - - - - -https://github.com/akkartik/mu/blob/master/066print-int.subx -
-  1 # Print the (hex) textual representation of numbers.
-  2 
-  3 == code
-  4 #   instruction                     effective address                                                   register    displacement    immediate
-  5 # . op          subop               mod             rm32          base        index         scale       r32
-  6 # . 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
-  7 
-  8 # convert the lowest nibble of eax to ascii and return it in the lowest byte of eax
-  9 to-hex-char:  # in/eax: int -> out/eax: int
- 10     # no error checking; accepts argument in eax
- 11     # if (eax <= 9) return eax + '0'
- 12     3d/compare-eax-with  0x9/imm32/9
- 13     7f/jump-if->  $to-hex-char:else/disp8
- 14     05/add-to-eax  0x30/imm32/0
- 15     c3/return
- 16 $to-hex-char:else:
- 17     # otherwise return eax + 'a' - 10
- 18     05/add-to-eax  0x57/imm32/a-10
- 19     c3/return
- 20 
- 21 append-byte-hex:  # f: (addr stream byte), n: int
- 22     # . prologue
- 23     55/push-ebp
- 24     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
- 25     # . save registers
- 26     50/push-eax
- 27     # AL = convert upper nibble to hex
- 28     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
- 29     c1/shift    5/subop/logic-right 3/mod/direct    0/rm32/eax    .           .             .           .           .               4/imm8            # shift eax right by 4 bits, while padding zeroes
- 30     25/and-eax  0xf/imm32
- 31     # . AL = to-hex-char(AL)
- 32     e8/call  to-hex-char/disp32
- 33     # append-byte(f, AL)
- 34     # . . push args
- 35     50/push-eax
- 36     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
- 37     # . . call
- 38     e8/call  append-byte/disp32
- 39     # . . discard args
- 40     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
- 41     # AL = convert lower nibble to hex
- 42     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
- 43     25/and-eax  0xf/imm32
- 44     # . AL = to-hex-char(AL)
- 45     e8/call  to-hex-char/disp32
- 46     # append-byte(f, AL)
- 47     # . . push args
- 48     50/push-eax
- 49     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
- 50     # . . call
- 51     e8/call  append-byte/disp32
- 52     # . . discard args
- 53     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
- 54 $append-byte-hex:end:
- 55     # . restore registers
- 56     58/pop-to-eax
- 57     # . epilogue
- 58     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
- 59     5d/pop-to-ebp
- 60     c3/return
- 61 
- 62 test-append-byte-hex:
- 63     # - check that append-byte-hex adds the hex textual representation
- 64     # setup
- 65     # . clear-stream(_test-stream)
- 66     # . . push args
- 67     68/push  _test-stream/imm32
- 68     # . . call
- 69     e8/call  clear-stream/disp32
- 70     # . . discard args
- 71     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
- 72     # append-byte-hex(_test-stream, 0xa)  # exercises digit, non-digit as well as leading zero
- 73     # . . push args
- 74     68/push  0xa/imm32
- 75     68/push  _test-stream/imm32
- 76     # . . call
- 77     e8/call  append-byte-hex/disp32
- 78     # . . discard args
- 79     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
- 80     # check-stream-equal(_test-stream, "0a", msg)
- 81     # . . push args
- 82     68/push  "F - test-append-byte-hex"/imm32
- 83     68/push  "0a"/imm32
- 84     68/push  _test-stream/imm32
- 85     # . . call
- 86     e8/call  check-stream-equal/disp32
- 87     # . . discard args
- 88     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
- 89     # . end
- 90     c3/return
- 91 
- 92 # print the hex representation for the lowest byte of a number
- 93 print-byte-buffered:  # f: (addr buffered-file), n: int
- 94     # . prologue
- 95     55/push-ebp
- 96     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
- 97     # . save registers
- 98     50/push-eax
- 99     # AL = convert upper nibble to hex
-100     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
-101     c1/shift    5/subop/logic-right 3/mod/direct    0/rm32/eax    .           .             .           .           .               4/imm8            # shift eax right by 4 bits, while padding zeroes
-102     25/and-eax  0xf/imm32
-103     # . AL = to-hex-char(AL)
-104     e8/call  to-hex-char/disp32
-105     # write-byte-buffered(f, AL)
-106     # . . push args
-107     50/push-eax
-108     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
-109     # . . call
-110     e8/call  write-byte-buffered/disp32
-111     # . . discard args
-112     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-113     # AL = convert lower nibble to hex
-114     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
-115     25/and-eax  0xf/imm32
-116     # . AL = to-hex-char(AL)
-117     e8/call  to-hex-char/disp32
-118     # write-byte-buffered(f, AL)
-119     # . . push args
-120     50/push-eax
-121     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
-122     # . . call
-123     e8/call  write-byte-buffered/disp32
-124     # . . discard args
-125     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-126 $print-byte-buffered:end:
-127     # . restore registers
-128     58/pop-to-eax
-129     # . epilogue
-130     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
-131     5d/pop-to-ebp
-132     c3/return
-133 
-134 test-print-byte-buffered:
-135     # - check that print-byte-buffered prints the hex textual representation
-136     # setup
-137     # . clear-stream(_test-stream)
-138     # . . push args
-139     68/push  _test-stream/imm32
-140     # . . call
-141     e8/call  clear-stream/disp32
-142     # . . discard args
-143     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
-144     # . clear-stream($_test-buffered-file->buffer)
-145     # . . push args
-146     68/push  $_test-buffered-file->buffer/imm32
-147     # . . call
-148     e8/call  clear-stream/disp32
-149     # . . discard args
-150     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
-151     # print-byte-buffered(_test-buffered-file, 0xa)  # exercises digit, non-digit as well as leading zero
-152     # . . push args
-153     68/push  0xa/imm32
-154     68/push  _test-buffered-file/imm32
-155     # . . call
-156     e8/call  print-byte-buffered/disp32
-157     # . . discard args
-158     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-159     # flush(_test-buffered-file)
-160     # . . push args
-161     68/push  _test-buffered-file/imm32
-162     # . . call
-163     e8/call  flush/disp32
-164     # . . discard args
-165     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
-166     # check-stream-equal(_test-stream, "0a", msg)
-167     # . . push args
-168     68/push  "F - test-print-byte-buffered"/imm32
-169     68/push  "0a"/imm32
-170     68/push  _test-stream/imm32
-171     # . . call
-172     e8/call  check-stream-equal/disp32
-173     # . . discard args
-174     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
-175     # . end
-176     c3/return
-177 
-178 print-int32:  # f: (addr stream byte), n: int
-179     # pseudocode:
-180     #  write(f, "0x")
-181     #  ecx = 28
-182     #  while true
-183     #    if (ecx < 0) break
-184     #    eax = n >> ecx
-185     #    eax = eax & 0xf
-186     #    append-byte(f, AL)
-187     #    ecx -= 4
-188     #
-189     # . prologue
-190     55/push-ebp
-191     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
-192     # . save registers
-193     50/push-eax
-194     51/push-ecx
-195     # ecx = 28
-196     b9/copy-to-ecx  0x1c/imm32
-197 $print-int32:print-hex-prefix:
-198     # write(f, "0x")
-199     # . . push args
-200     68/push  "0x"/imm32
-201     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
-202     # . . call
-203     e8/call  write/disp32
-204     # . . discard args
-205     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-206 $print-int32:loop:
-207     # if (ecx < 0) break
-208     81          7/subop/compare     3/mod/direct    1/rm32/ecx    .           .             .           .           .               0/imm32           # compare ecx
-209     7c/jump-if-<  $print-int32:end/disp8
-210     # eax = n >> ecx
-211     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
-212     d3/>>ecx    5/subop/pad-zeroes  3/mod/direct    0/rm32/eax    .           .             .           .           .               .                 # shift eax right by ecx bits, padding zeroes
-213     # eax = to-hex-char(AL)
-214     25/and-eax  0xf/imm32
-215     e8/call  to-hex-char/disp32
-216     # append-byte(f, AL)
-217     # . . push args
-218     50/push-eax
-219     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
-220     # . . call
-221     e8/call  append-byte/disp32
-222     # . . discard args
-223     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-224     # ecx -= 4
-225     81          5/subop/subtract    3/mod/direct    1/rm32/ecx    .           .             .           .           .               4/imm32           # subtract from ecx
-226     eb/jump  $print-int32:loop/disp8
-227 $print-int32:end:
-228     # . restore registers
-229     59/pop-to-ecx
-230     58/pop-to-eax
-231     # . epilogue
-232     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
-233     5d/pop-to-ebp
-234     c3/return
-235 
-236 test-print-int32:
-237     # - check that print-int32 prints the hex textual representation
-238     # setup
-239     # . clear-stream(_test-stream)
-240     # . . push args
-241     68/push  _test-stream/imm32
-242     # . . call
-243     e8/call  clear-stream/disp32
-244     # . . discard args
-245     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
-246     # print-int32(_test-stream, 0x8899aa)
-247     # . . push args
-248     68/push  0x8899aa/imm32
-249     68/push  _test-stream/imm32
-250     # . . call
-251     e8/call  print-int32/disp32
-252     # . . discard args
-253     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-254     # check-stream-equal(_test-stream, "0x008899aa", msg)
-255     # . . push args
-256     68/push  "F - test-print-int32"/imm32
-257     68/push  "0x008899aa"/imm32
-258     68/push  _test-stream/imm32
-259     # . . call
-260     e8/call  check-stream-equal/disp32
-261     # . . discard args
-262     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
-263     # . end
-264     c3/return
-265 
-266 print-int32-buffered:  # f: (addr buffered-file), n: int
-267     # pseudocode:
-268     #  write-buffered(f, "0x")
-269     #  ecx = 28
-270     #  while true
-271     #    if (ecx < 0) break
-272     #    eax = n >> ecx
-273     #    eax = eax & 0xf
-274     #    write-byte-buffered(f, AL)
-275     #    ecx -= 4
-276     #
-277     # . prologue
-278     55/push-ebp
-279     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
-280     # . save registers
-281     50/push-eax
-282     51/push-ecx
-283     # ecx = 28
-284     b9/copy-to-ecx  0x1c/imm32
-285 $print-int32-buffered:print-hex-prefix:
-286     # write-buffered(f, "0x")
-287     # . . push args
-288     68/push  "0x"/imm32
-289     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
-290     # . . call
-291     e8/call  write-buffered/disp32
-292     # . . discard args
-293     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-294 $print-int32-buffered:loop:
-295     # if (ecx < 0) break
-296     81          7/subop/compare     3/mod/direct    1/rm32/ecx    .           .             .           .           .               0/imm32           # compare ecx
-297     7c/jump-if-<  $print-int32-buffered:end/disp8
-298     # eax = n >> ecx
-299     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
-300     d3/>>ecx    5/subop/pad-zeroes  3/mod/direct    0/rm32/eax    .           .             .           .           .               .                 # shift eax right by ecx bits, padding zeroes
-301     # eax = to-hex-char(AL)
-302     25/and-eax  0xf/imm32
-303     e8/call  to-hex-char/disp32
-304     # write-byte-buffered(f, AL)
-305     # . . push args
-306     50/push-eax
-307     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
-308     # . . call
-309     e8/call  write-byte-buffered/disp32
-310     # . . discard args
-311     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-312     # ecx -= 4
-313     81          5/subop/subtract    3/mod/direct    1/rm32/ecx    .           .             .           .           .               4/imm32           # subtract from ecx
-314     eb/jump  $print-int32-buffered:loop/disp8
-315 $print-int32-buffered:end:
-316     # . restore registers
-317     59/pop-to-ecx
-318     58/pop-to-eax
-319     # . epilogue
-320     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
-321     5d/pop-to-ebp
-322     c3/return
-323 
-324 test-print-int32-buffered:
-325     # - check that print-int32-buffered prints the hex textual representation
-326     # setup
-327     # . clear-stream(_test-stream)
-328     # . . push args
-329     68/push  _test-stream/imm32
-330     # . . call
-331     e8/call  clear-stream/disp32
-332     # . . discard args
-333     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
-334     # . clear-stream($_test-buffered-file->buffer)
-335     # . . push args
-336     68/push  $_test-buffered-file->buffer/imm32
-337     # . . call
-338     e8/call  clear-stream/disp32
-339     # . . discard args
-340     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
-341     # print-int32-buffered(_test-buffered-file, 0x8899aa)
-342     # . . push args
-343     68/push  0x8899aa/imm32
-344     68/push  _test-buffered-file/imm32
-345     # . . call
-346     e8/call  print-int32-buffered/disp32
-347     # . . discard args
-348     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-349     # flush(_test-buffered-file)
-350     # . . push args
-351     68/push  _test-buffered-file/imm32
-352     # . . call
-353     e8/call  flush/disp32
-354     # . . discard args
-355     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
-356 +-- 18 lines: #?     # dump line --------------------------------------------------------------------------------------------------------------------------------------------------------
-374     # check-stream-equal(_test-stream, "0x008899aa", msg)
-375     # . . push args
-376     68/push  "F - test-print-int32-buffered"/imm32
-377     68/push  "0x008899aa"/imm32
-378     68/push  _test-stream/imm32
-379     # . . call
-380     e8/call  check-stream-equal/disp32
-381     # . . discard args
-382     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
-383     # . end
-384     c3/return
-385 
-386 # . . vim:nowrap:textwidth=0
-
- - - diff --git a/html/066write-int-hex.subx.html b/html/066write-int-hex.subx.html new file mode 100644 index 00000000..dac46129 --- /dev/null +++ b/html/066write-int-hex.subx.html @@ -0,0 +1,434 @@ + + + + +Mu - 066print-int.subx + + + + + + + + + + +https://github.com/akkartik/mu/blob/master/066print-int.subx +
+  1 # Print the (hex) textual representation of numbers.
+  2 
+  3 == code
+  4 #   instruction                     effective address                                                   register    displacement    immediate
+  5 # . op          subop               mod             rm32          base        index         scale       r32
+  6 # . 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
+  7 
+  8 # convert the lowest nibble of eax to ascii and return it in the lowest byte of eax
+  9 to-hex-char:  # in/eax: int -> out/eax: int
+ 10     # no error checking; accepts argument in eax
+ 11     # if (eax <= 9) return eax + '0'
+ 12     3d/compare-eax-with  0x9/imm32/9
+ 13     7f/jump-if->  $to-hex-char:else/disp8
+ 14     05/add-to-eax  0x30/imm32/0
+ 15     c3/return
+ 16 $to-hex-char:else:
+ 17     # otherwise return eax + 'a' - 10
+ 18     05/add-to-eax  0x57/imm32/a-10
+ 19     c3/return
+ 20 
+ 21 append-byte-hex:  # f: (addr stream byte), n: int
+ 22     # . prologue
+ 23     55/push-ebp
+ 24     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+ 25     # . save registers
+ 26     50/push-eax
+ 27     # AL = convert upper nibble to hex
+ 28     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
+ 29     c1/shift    5/subop/logic-right 3/mod/direct    0/rm32/eax    .           .             .           .           .               4/imm8            # shift eax right by 4 bits, while padding zeroes
+ 30     25/and-eax  0xf/imm32
+ 31     # . AL = to-hex-char(AL)
+ 32     e8/call  to-hex-char/disp32
+ 33     # append-byte(f, AL)
+ 34     # . . push args
+ 35     50/push-eax
+ 36     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
+ 37     # . . call
+ 38     e8/call  append-byte/disp32
+ 39     # . . discard args
+ 40     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+ 41     # AL = convert lower nibble to hex
+ 42     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
+ 43     25/and-eax  0xf/imm32
+ 44     # . AL = to-hex-char(AL)
+ 45     e8/call  to-hex-char/disp32
+ 46     # append-byte(f, AL)
+ 47     # . . push args
+ 48     50/push-eax
+ 49     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
+ 50     # . . call
+ 51     e8/call  append-byte/disp32
+ 52     # . . discard args
+ 53     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+ 54 $append-byte-hex:end:
+ 55     # . restore registers
+ 56     58/pop-to-eax
+ 57     # . epilogue
+ 58     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
+ 59     5d/pop-to-ebp
+ 60     c3/return
+ 61 
+ 62 test-append-byte-hex:
+ 63     # - check that append-byte-hex adds the hex textual representation
+ 64     # setup
+ 65     # . clear-stream(_test-stream)
+ 66     # . . push args
+ 67     68/push  _test-stream/imm32
+ 68     # . . call
+ 69     e8/call  clear-stream/disp32
+ 70     # . . discard args
+ 71     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+ 72     # append-byte-hex(_test-stream, 0xa)  # exercises digit, non-digit as well as leading zero
+ 73     # . . push args
+ 74     68/push  0xa/imm32
+ 75     68/push  _test-stream/imm32
+ 76     # . . call
+ 77     e8/call  append-byte-hex/disp32
+ 78     # . . discard args
+ 79     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+ 80     # check-stream-equal(_test-stream, "0a", msg)
+ 81     # . . push args
+ 82     68/push  "F - test-append-byte-hex"/imm32
+ 83     68/push  "0a"/imm32
+ 84     68/push  _test-stream/imm32
+ 85     # . . call
+ 86     e8/call  check-stream-equal/disp32
+ 87     # . . discard args
+ 88     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+ 89     # . end
+ 90     c3/return
+ 91 
+ 92 # print the hex representation for the lowest byte of a number
+ 93 print-byte-buffered:  # f: (addr buffered-file), n: int
+ 94     # . prologue
+ 95     55/push-ebp
+ 96     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+ 97     # . save registers
+ 98     50/push-eax
+ 99     # AL = convert upper nibble to hex
+100     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
+101     c1/shift    5/subop/logic-right 3/mod/direct    0/rm32/eax    .           .             .           .           .               4/imm8            # shift eax right by 4 bits, while padding zeroes
+102     25/and-eax  0xf/imm32
+103     # . AL = to-hex-char(AL)
+104     e8/call  to-hex-char/disp32
+105     # write-byte-buffered(f, AL)
+106     # . . push args
+107     50/push-eax
+108     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
+109     # . . call
+110     e8/call  write-byte-buffered/disp32
+111     # . . discard args
+112     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+113     # AL = convert lower nibble to hex
+114     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
+115     25/and-eax  0xf/imm32
+116     # . AL = to-hex-char(AL)
+117     e8/call  to-hex-char/disp32
+118     # write-byte-buffered(f, AL)
+119     # . . push args
+120     50/push-eax
+121     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
+122     # . . call
+123     e8/call  write-byte-buffered/disp32
+124     # . . discard args
+125     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+126 $print-byte-buffered:end:
+127     # . restore registers
+128     58/pop-to-eax
+129     # . epilogue
+130     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
+131     5d/pop-to-ebp
+132     c3/return
+133 
+134 test-print-byte-buffered:
+135     # - check that print-byte-buffered prints the hex textual representation
+136     # setup
+137     # . clear-stream(_test-stream)
+138     # . . push args
+139     68/push  _test-stream/imm32
+140     # . . call
+141     e8/call  clear-stream/disp32
+142     # . . discard args
+143     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+144     # . clear-stream($_test-buffered-file->buffer)
+145     # . . push args
+146     68/push  $_test-buffered-file->buffer/imm32
+147     # . . call
+148     e8/call  clear-stream/disp32
+149     # . . discard args
+150     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+151     # print-byte-buffered(_test-buffered-file, 0xa)  # exercises digit, non-digit as well as leading zero
+152     # . . push args
+153     68/push  0xa/imm32
+154     68/push  _test-buffered-file/imm32
+155     # . . call
+156     e8/call  print-byte-buffered/disp32
+157     # . . discard args
+158     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+159     # flush(_test-buffered-file)
+160     # . . push args
+161     68/push  _test-buffered-file/imm32
+162     # . . call
+163     e8/call  flush/disp32
+164     # . . discard args
+165     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+166     # check-stream-equal(_test-stream, "0a", msg)
+167     # . . push args
+168     68/push  "F - test-print-byte-buffered"/imm32
+169     68/push  "0a"/imm32
+170     68/push  _test-stream/imm32
+171     # . . call
+172     e8/call  check-stream-equal/disp32
+173     # . . discard args
+174     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+175     # . end
+176     c3/return
+177 
+178 print-int32:  # f: (addr stream byte), n: int
+179     # pseudocode:
+180     #  write(f, "0x")
+181     #  ecx = 28
+182     #  while true
+183     #    if (ecx < 0) break
+184     #    eax = n >> ecx
+185     #    eax = eax & 0xf
+186     #    append-byte(f, AL)
+187     #    ecx -= 4
+188     #
+189     # . prologue
+190     55/push-ebp
+191     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+192     # . save registers
+193     50/push-eax
+194     51/push-ecx
+195     # ecx = 28
+196     b9/copy-to-ecx  0x1c/imm32
+197 $print-int32:print-hex-prefix:
+198     # write(f, "0x")
+199     # . . push args
+200     68/push  "0x"/imm32
+201     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
+202     # . . call
+203     e8/call  write/disp32
+204     # . . discard args
+205     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+206 $print-int32:loop:
+207     # if (ecx < 0) break
+208     81          7/subop/compare     3/mod/direct    1/rm32/ecx    .           .             .           .           .               0/imm32           # compare ecx
+209     7c/jump-if-<  $print-int32:end/disp8
+210     # eax = n >> ecx
+211     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
+212     d3/>>ecx    5/subop/pad-zeroes  3/mod/direct    0/rm32/eax    .           .             .           .           .               .                 # shift eax right by ecx bits, padding zeroes
+213     # eax = to-hex-char(AL)
+214     25/and-eax  0xf/imm32
+215     e8/call  to-hex-char/disp32
+216     # append-byte(f, AL)
+217     # . . push args
+218     50/push-eax
+219     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
+220     # . . call
+221     e8/call  append-byte/disp32
+222     # . . discard args
+223     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+224     # ecx -= 4
+225     81          5/subop/subtract    3/mod/direct    1/rm32/ecx    .           .             .           .           .               4/imm32           # subtract from ecx
+226     eb/jump  $print-int32:loop/disp8
+227 $print-int32:end:
+228     # . restore registers
+229     59/pop-to-ecx
+230     58/pop-to-eax
+231     # . epilogue
+232     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
+233     5d/pop-to-ebp
+234     c3/return
+235 
+236 test-print-int32:
+237     # - check that print-int32 prints the hex textual representation
+238     # setup
+239     # . clear-stream(_test-stream)
+240     # . . push args
+241     68/push  _test-stream/imm32
+242     # . . call
+243     e8/call  clear-stream/disp32
+244     # . . discard args
+245     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+246     # print-int32(_test-stream, 0x8899aa)
+247     # . . push args
+248     68/push  0x8899aa/imm32
+249     68/push  _test-stream/imm32
+250     # . . call
+251     e8/call  print-int32/disp32
+252     # . . discard args
+253     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+254     # check-stream-equal(_test-stream, "0x008899aa", msg)
+255     # . . push args
+256     68/push  "F - test-print-int32"/imm32
+257     68/push  "0x008899aa"/imm32
+258     68/push  _test-stream/imm32
+259     # . . call
+260     e8/call  check-stream-equal/disp32
+261     # . . discard args
+262     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+263     # . end
+264     c3/return
+265 
+266 print-int32-buffered:  # f: (addr buffered-file), n: int
+267     # pseudocode:
+268     #  write-buffered(f, "0x")
+269     #  ecx = 28
+270     #  while true
+271     #    if (ecx < 0) break
+272     #    eax = n >> ecx
+273     #    eax = eax & 0xf
+274     #    write-byte-buffered(f, AL)
+275     #    ecx -= 4
+276     #
+277     # . prologue
+278     55/push-ebp
+279     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+280     # . save registers
+281     50/push-eax
+282     51/push-ecx
+283     # ecx = 28
+284     b9/copy-to-ecx  0x1c/imm32
+285 $print-int32-buffered:print-hex-prefix:
+286     # write-buffered(f, "0x")
+287     # . . push args
+288     68/push  "0x"/imm32
+289     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
+290     # . . call
+291     e8/call  write-buffered/disp32
+292     # . . discard args
+293     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+294 $print-int32-buffered:loop:
+295     # if (ecx < 0) break
+296     81          7/subop/compare     3/mod/direct    1/rm32/ecx    .           .             .           .           .               0/imm32           # compare ecx
+297     7c/jump-if-<  $print-int32-buffered:end/disp8
+298     # eax = n >> ecx
+299     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
+300     d3/>>ecx    5/subop/pad-zeroes  3/mod/direct    0/rm32/eax    .           .             .           .           .               .                 # shift eax right by ecx bits, padding zeroes
+301     # eax = to-hex-char(AL)
+302     25/and-eax  0xf/imm32
+303     e8/call  to-hex-char/disp32
+304     # write-byte-buffered(f, AL)
+305     # . . push args
+306     50/push-eax
+307     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
+308     # . . call
+309     e8/call  write-byte-buffered/disp32
+310     # . . discard args
+311     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+312     # ecx -= 4
+313     81          5/subop/subtract    3/mod/direct    1/rm32/ecx    .           .             .           .           .               4/imm32           # subtract from ecx
+314     eb/jump  $print-int32-buffered:loop/disp8
+315 $print-int32-buffered:end:
+316     # . restore registers
+317     59/pop-to-ecx
+318     58/pop-to-eax
+319     # . epilogue
+320     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
+321     5d/pop-to-ebp
+322     c3/return
+323 
+324 test-print-int32-buffered:
+325     # - check that print-int32-buffered prints the hex textual representation
+326     # setup
+327     # . clear-stream(_test-stream)
+328     # . . push args
+329     68/push  _test-stream/imm32
+330     # . . call
+331     e8/call  clear-stream/disp32
+332     # . . discard args
+333     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+334     # . clear-stream($_test-buffered-file->buffer)
+335     # . . push args
+336     68/push  $_test-buffered-file->buffer/imm32
+337     # . . call
+338     e8/call  clear-stream/disp32
+339     # . . discard args
+340     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+341     # print-int32-buffered(_test-buffered-file, 0x8899aa)
+342     # . . push args
+343     68/push  0x8899aa/imm32
+344     68/push  _test-buffered-file/imm32
+345     # . . call
+346     e8/call  print-int32-buffered/disp32
+347     # . . discard args
+348     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+349     # flush(_test-buffered-file)
+350     # . . push args
+351     68/push  _test-buffered-file/imm32
+352     # . . call
+353     e8/call  flush/disp32
+354     # . . discard args
+355     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
+356 +-- 18 lines: #?     # dump line --------------------------------------------------------------------------------------------------------------------------------------------------------
+374     # check-stream-equal(_test-stream, "0x008899aa", msg)
+375     # . . push args
+376     68/push  "F - test-print-int32-buffered"/imm32
+377     68/push  "0x008899aa"/imm32
+378     68/push  _test-stream/imm32
+379     # . . call
+380     e8/call  check-stream-equal/disp32
+381     # . . discard args
+382     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+383     # . end
+384     c3/return
+385 
+386 # . . vim:nowrap:textwidth=0
+
+ + + -- cgit 1.4.1-2-gfad0