https://github.com/akkartik/mu/blob/main/112read-byte.subx
  1 # Read a single byte from a stream.
  2 #
  3 # We need to do this in machine code because streams need to be opaque types,
  4 # and we don't yet support opaque types in Mu.
  5 
  6 == code
  7 #   instruction                     effective address                                                   register    displacement    immediate
  8 # . op          subop               mod             rm32          base        index         scale       r32
  9 # . 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
 10 
 11 # Return next byte value in eax, with top 3 bytes cleared.
 12 # Abort on reaching end of stream.
 13 read-byte:  # s: (addr stream byte) -> result/eax: byte
 14     # . prologue
 15     55/push-ebp
 16     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
 17     # . save registers
 18     51/push-ecx
 19     56/push-esi
 20     # esi = s
 21     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
 22     # ecx = s->read
 23     8b/copy                         1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   4/disp8         .                 # copy *(esi+4) to ecx
 24     # if (f->read >= f->write) abort
 25     3b/compare                      0/mod/indirect  6/rm32/esi    .           .             .           1/r32/ecx   .               .                 # compare ecx with *esi
 26     0f 8d/jump-if->=  $read-byte:abort/disp32
 27     # result = f->data[f->read]
 28     31/xor                          3/mod/direct    0/rm32/eax    .           .             .           0/r32/eax   .         
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mu - linux/apps/ex3.mu</title>
<meta name="Generator" content="Vim/8.2">
<meta name="plugin-version" content="vim8.1_v2">
<meta name="syntax" content="none">
<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy=,use_input_for_pc=fallback">
<meta name="colorscheme" content="minimal-light">
<style>
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #ffffd7; }
body { font-size:12pt; font-family: monospace; color: #000000; background-color: #ffffd7; }
a { color:inherit; }