https://github.com/akkartik/mu/blob/main/baremetal/112read-byte.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 # TODO: read-byte-buffered
 7 
 8 # Return next byte value in eax, with top 3 bytes cleared.
 9 # Abort on reaching end of stream.
10 read-byte:  # s: (addr stream byte) -> result/eax: byte
11     # . prologue
12     55/push-ebp
13     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
14     # . save registers
15     51/push-ecx
16     56/push-esi
17     # esi = s
18     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
19     # ecx = s->read
20     8b/copy                         1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   4/disp8         .                 # copy *(esi+4) to ecx
21     # if (f->read >= f->write) abort
22     3b/compare                      0/mod/indirect  6/rm32/esi    .           .             .           1/r32/ecx   .               .                 # compare ecx with *esi
23     0f 8d/jump-if->=  $read-byte:end/disp32  # TODO: abort
24     # result = f->data[f->read]
25     31/xor                          3/mod/direct    0/rm32/eax    .           .             .           0/r32/eax   .               .                 # clear eax
26     8a/copy-byte                    1/mod/*+disp8   4/rm32/sib    6/base/esi  1/index/ecx   .           0/r32/AL    0xc/disp8       .                 # copy byte at *(esi+ecx+12) to AL
27     # ++f->read
28     ff          0/subop/increment   1/mod/*+disp8   6/rm32/esi    .           .             .           .           4/disp8         .                 # increment *(esi+4)
29 $read-byte:end:
30     # . restore registers
31     5e/pop-to-esi
32     59/pop-to-ecx
33     # . epilogue
34     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
35     5d/pop-to-ebp
36     c3/return
37 
38 # . . vim:nowrap:textwidth=0