https://github.com/akkartik/mu/blob/master/084emit-hex-array.subx
  1 == code
  2 #   instruction                     effective address                                                   register    displacement    immediate
  3 # . op          subop               mod             rm32          base        index         scale       r32
  4 # . 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
  5 
  6 # print 'arr' in hex with a space after every byte
  7 emit-hex-array:  # out : (address buffered-file), arr : (address array byte) -> <void>
  8     # . prolog
  9     55/push-ebp
 10     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
 11     # . save registers
 12     50/push-eax
 13     51/push-ecx
 14     52/push-edx
 15     57/push-edi
 16     # edi = out
 17     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           7/r32/edi   8/disp8         .                 # copy *(ebp+8) to edi
 18     # edx = arr  # <== 0xbdffffe4
 19     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           2/r32/edx   0xc/disp8       .                 # copy *(ebp+12) to edx
 20     # curr/ecx = arr->data
 21     8d/copy-address                 1/mod/*+disp8   2/rm32/edx    .           .             .           1/r32/ecx   4/disp8         .                 # copy edx+4 to ecx
 22     # max/edx = arr->data + arr->length
 23     8b/copy                         0/mod/indirect  2/rm32/edx    .           .             .           2/r32/edx   .               .                 # copy *edx to edx
 24     01/add                          3/mod/direct    2/rm32/edx    .           .             .           1/r32/ecx   .               .                 # add ecx to edx
 25     # eax = 0
 26     31/xor                          3/mod/direct    0/rm32/eax    .           .             .           0/r32/eax   .               .                 # clear eax
 27 $emit-hex-array:loop:
 28     # if (curr >= width) break
 29     39/compare                      3/mod/direct    1/rm32/ecx    .           .             .           2/r32/edx   .               .                 # compare ecx with edx
 30     73/jump-if-greater-or-equal-unsigned  $emit-hex-array:end/disp8
 31     # emit-hex(out, *curr, width=1)
 32     # . . push args
 33     68/push  1/imm32/width
 34     8a/copy-byte                    0/mod/indirect  1/rm32/ecx    .           .             .           0/r32/AL    .               .                 # copy byte at *ecx to AL
 35     50/push-eax
 36     57/push-edi
 37     # . . call
 38     e8/call  emit-hex/disp32
 39     # . . discard args
 40     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
 41     # ++curr
 42     41/increment-ecx
 43     eb/jump  $emit-hex-array:loop/disp8
 44 $emit-hex-array:end:
 45     # . restore registers
 46     5f/pop-to-edi
 47     5a/pop-to-edx
 48     59/pop-to-ecx
 49     58/pop-to-eax
 50     # . epilog
 51     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
 52     5d/pop-to-ebp
 53     c3/return
 54 
 55 test-emit-hex-array:
 56     # . prolog
 57     55/push-ebp
 58     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
 59     # setup
 60     # . clear-stream(_test-output-stream)
 61     # . . push args
 62     68/push  _test-output-stream/imm32
 63     # . . call
 64     e8/call  clear-stream/disp32
 65     # . . discard args
 66     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
 67     # . clear-stream(_test-output-buffered-file+4)
 68     # . . push args
 69     b8/copy-to-eax  _test-output-buffered-file/imm32
 70     05/add-to-eax  4/imm32
 71     50/push-eax
 72     # . . call
 73     e8/call  clear-stream/disp32
 74     # . . discard args
 75     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
 76     # var arr/ecx (address array byte) = [01, 02, 03]
 77     68/push  0x00030201/imm32  # bytes 01 02 03
 78     68/push  3/imm32/length
 79     89/copy                         3/mod/direct    1/rm32/ecx    .           .             .           4/r32/esp   .               .                 # copy esp to ecx
 80     # emit-hex-array(_test-output-buffered-file, arr)
 81     # . . push args
 82     51/push-ecx
 83     68/push  _test-output-buffered-file/imm32
 84     # . . call
 85     e8/call  emit-hex-array/disp32
 86     # . . discard args
 87     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
 88     # . flush(_test-output-buffered-file)
 89     # . . push args
 90     68/push  _test-output-buffered-file/imm32
 91     # . . call
 92     e8/call  flush/disp32
 93     # . . discard args
 94     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
 95 +-- 33 lines: #?     # dump output ---------------------------------------------------------------------------------------------------------------------------
128     # check-next-stream-line-equal(_test-output-stream, "01 02 03 ", msg)
129     # . . push args
130     68/push  "F - test-emit-hex-array"/imm32
131     68/push  "01 02 03 "/imm32
132     68/push  _test-output-stream/imm32
133     # . . call
134     e8/call  check-next-stream-line-equal/disp32
135     # . . discard args
136     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
137     # . epilog
138     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
139     5d/pop-to-ebp
140     c3/return
141 
142 # . . vim:nowrap:textwidth=0