https://github.com/akkartik/mu/blob/master/subx/068error-byte.subx

      1 # Print an error message followed by the text representation of a byte. Then exit.
      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 #? Entry:  # manual test
      9 #?     # . var ed/EAX : exit-descriptor
     10 #?     81          5/subop/subtract    3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # subtract from ESP
     11 #?     89/copy                         3/mod/direct    0/rm32/EAX    .           .             .           4/r32/ESP   .               .                 # copy ESP to EAX
     12 #?     # . configure ed to really exit()
     13 #?     # . . ed->target = 0
     14 #?     c7          0/subop/copy        0/mod/direct    0/rm32/EAX    .           .             .           .           .               0/imm32           # copy to *EAX
     15 #?     # . error-byte(ed, Stdout, msg, 34)
     16 #?     68/push  0x34/imm32
     17 #?     68/push  "abc"/imm32
     18 #?     68/push  Stderr/imm32
     19 #?     50/push-EAX
     20 #?     e8/call  error-byte/disp32
     21 #?     # . syscall(exit, Num-test-failures)
     22 #?     8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/EBX   Num-test-failures/disp32          # copy *Num-test-failures to EBX
     23 #?     b8/copy-to-EAX  1/imm32/exit
     24 #?     cd/syscall  0x80/imm8
     25
     26 # write(out, "Error: "+msg+": "+byte) then stop(ed, 1)
     27 error-byte:  # ed : (address exit-descriptor), out : (address buffered-file), msg : (address array byte), n : byte -> <void>
     28     # . prolog
     29     55/push-EBP
     30     89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
     31     # write-buffered(out, "Error: ")
     32     # . . push args
     33     68/push  "Error: "/imm32
     34     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
     35     # . . call
     36     e8/call  write-buffered/disp32
     37     # . . discard args
     38     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     39     # write-buffered(out, msg)
     40     # . . push args
     41     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x10/disp8      .                 # push *(EBP+16)
     42     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
     43     # . . call
     44     e8/call  write-buffered/disp32
     45     # . . discard args
     46     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     47     # write-buffered(out, ": ")
     48     # . . push args
     49     68/push  ": "/imm32
     50     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
     51     # . . call
     52     e8/call  write-buffered/disp32
     53     # . . discard args
     54     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     55     # print-byte(out, byte)
     56     # . . push args
     57     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x14/disp8      .                 # push *(EBP+20)
     58     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
     59     # . . call
     60     e8/call  print-byte/disp32
     61     # . . discard args
     62     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     63     # write-buffered(out, Newline)
     64     # . . push args
     65     68/push  Newline/imm32
     66     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
     67     # . . call
     68     e8/call  write-buffered/disp32
     69     # . . discard args
     70     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     71     # . flush(out)
     72     # . . push args
     73     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
     74     # . . call
     75     e8/call  flush/disp32
     76     # . . discard args
     77     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
     78     # stop(ed, 1)
     79     # . . push args
     80     68/push  1/imm32
     81     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
     82     # . . call
     83     e8/call  stop/disp32
     84     # should never get past this point
     85 $error-byte:dead-end:
     86     # . epilog
     87     89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
     88     5d/pop-to-EBP
     89     c3/return
     90
     91 == data
     92
     93 # The buffered file for standard error.
     94 Stderr:
     95     # file descriptor or (address stream)
     96     2/imm32  # standard error
     97     # current write index
     98     0/imm32
     99     # current read index
    100     0/imm32
    101     # length
    102     8/imm32
    103     # data
    104     00 00 00 00 00 00 00 00  # 8 bytes
    105
    106 # TODO: 8 bytes is too small. We'll need to grow the buffer for efficiency. But
    107 # I don't want to type in 1024 bytes here.
    108
    109 # . . vim:nowrap:textwidth=0