https://github.com/akkartik/mu/blob/master/051test.subx
 1 # Rudimentary test harness
 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     # check-ints-equal(34, 34)
10     # . . push args
11     68/push  "error in check-ints-equal"/imm32
12     68/push  34/imm32
13     68/push  34/imm32
14     # . . call
15     e8/call  check-ints-equal/disp32
16     # . . discard args
17     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
18     # syscall(exit, 0)
19     bb/copy-to-ebx  0/imm32
20     b8/copy-to-eax  1/imm32/exit
21     cd/syscall  0x80/imm8
22 
23 # print msg to stderr if a != b, otherwise print "."
24 check-ints-equal:  # (a : int, b : int, msg : (address array byte)) -> <void>
25     # . prolog
26     55/push-ebp
27     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
28     # . save registers
29     50/push-eax
30     51/push-ecx
31     53/push-ebx
32     # load first 2 args into eax and ebx
33     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   8/disp8         .                 # copy *(ebp+8) to eax
34     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           3/r32/ebx   0xc/disp8       .                 # copy *(ebp+12) to ebx
35     # if (eax == ebx) success
36     39/compare                      3/mod/direct    0/rm32/eax    .           .             .           3/r32/ebx   .               .                 # compare eax and ebx
37     75/jump-if-unequal  $check-ints-equal:else/disp8
38     # . _write(2/stderr, '.')
39     # . . push args
40     68/push  "."/imm32
41     68/push  2/imm32/stderr
42     # . . call
43     e8/call  _write/disp32
44     # . . discard args
45     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
46     # . return
47     eb/jump  $check-ints-equal:end/disp8
48     # otherwise print error message
49 $check-ints-equal:else:
50     # . _write(2/stderr, msg)
51     # . . push args
52     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # copy *(ebp+16) to ecx
53     51/push-ecx
54     68/push  2/imm32/stderr
55     # . . call
56     e8/call  _write/disp32
57     # . . discard args
58     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
59     # . _write(2/stderr, Newline)
60     # . . push args
61     68/push  Newline/imm32
62     68/push  2/imm32/stderr
63     # . . call
64     e8/call  _write/disp32
65     # . . discard args
66     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
67     # increment Num-test-failures
68     ff          0/subop/increment   0/mod/indirect  5/rm32/.disp32            .             .           .           Num-test-failures/disp32          # increment *Num-test-failures
69 $check-ints-equal:end:
70     # . restore registers
71     5b/pop-to-ebx
72     59/pop-to-ecx
73     58/pop-to-eax
74     # . epilog
75     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
76     5d/pop-to-ebp
77     c3/return
78 
79 == data
80 
81 # length-prefixed string containing just a single newline
82 # convenient to have when printing messages and so on
83 Newline:
84     # size
85     1/imm32
86     # data
87     0a/newline
88 
89 # every test failure increments this counter
90 Num-test-failures:
91     0/imm32
92 
93 # . . vim:nowrap:textwidth=0