https://github.com/akkartik/mu/blob/master/subx/056trace.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 == data
22
23
24 Trace-stream:
25 00 00 00 00
26
27
28
29 _test-trace-stream:
30
31 00 00 00 00
32
33 00 00 00 00
34
35 08 00 00 00
36
37 00 00 00 00 00 00 00 00
38
39 == code
40
41
42
43
44
45
46 e8/call run-tests/disp32
47
48 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32
49 b8/copy-to-EAX 1/imm32/exit
50 cd/syscall 0x80/imm8
51
52
53
54 initialize-trace-stream:
55
56
57 68/push 0x1000/imm32/N
58
59 e8/call new-segment/disp32
60
61 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
62
63 89/copy 0/mod/indirect 5/rm32/.disp32 . . 0/r32/EAX Trace-stream/disp32
64
65 c7 0/subop/copy 1/mod/*+disp8 0/rm32/EAX . . . . 8/disp8 0xff4/imm32
66 c3/return
67
68
69
70 trace:
71
72 55/push-EBP
73 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
74
75 50/push-EAX
76 51/push-ECX
77 52/push-EDX
78 53/push-EBX
79 56/push-ESI
80 57/push-EDI
81
82 8b/copy 1/mod/*+disp8 5/rm32/EBP . . 7/r32/EDI 8/disp8 .
83
84 8b/copy 1/mod/*+disp8 5/rm32/EBP . . 6/r32/ESI 0xc/disp8 .
85
86 8b/copy 0/mod/indirect 7/rm32/EDI . . . 1/r32/ECX . .
87
88 8b/copy 1/mod/*+disp8 7/rm32/EDI . . . 2/r32/EDX 8/disp8 .
89
90
91 56/push-ESI
92
93 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 2/index/EDX . 3/r32/EBX 0xc/disp8 .
94 53/push-EBX
95
96 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 1/index/ECX . 3/r32/EBX 0xc/disp8 .
97 53/push-EBX
98
99 e8/call _append-3/disp32
100
101 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
102
103 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0/imm32
104 74/jump-if-equal $trace:end/disp8
105
106 01/add 0/mod/indirect 7/rm32/EDI . . . 0/r32/EAX . .
107
108 8b/copy 0/mod/indirect 7/rm32/EDI . . . 1/r32/ECX . .
109
110
111 68/push Newline/imm32
112
113 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 2/index/EDX . 3/r32/EBX 0xc/disp8 .
114 53/push-EBX
115
116 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 1/index/ECX . 3/r32/EBX 0xc/disp8 .
117 53/push-EBX
118
119 e8/call _append-3/disp32
120
121 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
122
123 01/add 0/mod/indirect 7/rm32/EDI . . . 0/r32/EAX . .
124 $trace:end:
125
126 5f/pop-to-EDI
127 5e/pop-to-ESI
128 5b/pop-to-EBX
129 5a/pop-to-EDX
130 59/pop-to-ECX
131 58/pop-to-EAX
132
133 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
134 5d/pop-to-EBP
135 c3/return
136
137 clear-trace-stream:
138
139 55/push-EBP
140 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
141
142 50/push-EAX
143 51/push-ECX
144
145 8b/copy 1/mod/*+disp8 5/rm32/EBP . . 0/r32/EAX 8/disp8 .
146
147 8b/copy 1/mod/*+disp8 0/rm32/EAX . . . 1/r32/ECX 8/disp8 .
148
149 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX . 1/r32/ECX 0xc/disp8 .
150
151 c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32
152
153 c7 0/subop/copy 1/mod/*+disp8 0/rm32/EAX . . . . 4/disp8 0/imm32
154
155 81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 0xc/imm32
156
157 $clear-trace-stream:loop:
158
159 39/compare 3/mod/direct 0/rm32/EAX . . . 1/r32/ECX . .
160 7d/jump-if-greater-or-equal $clear-trace-stream:end/disp8
161
162 c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32
163
164 81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 4/imm32
165 eb/jump $clear-trace-stream:loop/disp8
166 $clear-trace-stream:end:
167
168 59/pop-to-ECX
169 58/pop-to-EAX
170
171 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
172 5d/pop-to-EBP
173 c3/return
174
175
176
177 test-trace-single:
178
179
180 68/push _test-trace-stream/imm32
181
182 e8/call clear-trace-stream/disp32
183
184 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
185
186
187 68/push "Ab"/imm32
188 68/push _test-trace-stream/imm32
189
190 e8/call trace/disp32
191
192 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
193
194
195 68/push "F - test-trace-single"/imm32
196 68/push 0x0a6241/imm32/Ab-newline
197
198 b8/copy-to-EAX _test-trace-stream/imm32
199 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 .
200
201 e8/call check-ints-equal/disp32
202
203 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
204
205 c3/return
206
207 test-trace-appends:
208
209
210 68/push _test-trace-stream/imm32
211
212 e8/call clear-trace-stream/disp32
213
214 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
215
216
217 68/push "C"/imm32
218 68/push _test-trace-stream/imm32
219
220 e8/call trace/disp32
221
222 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
223
224
225 68/push "D"/imm32
226 68/push _test-trace-stream/imm32
227
228 e8/call trace/disp32
229
230 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
231
232
233 68/push "F - test-trace-appends"/imm32
234 68/push 0x0a440a43/imm32/C-newline-D-newline
235
236 b8/copy-to-EAX _test-trace-stream/imm32
237 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 .
238
239 e8/call check-ints-equal/disp32
240
241 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
242
243 c3/return
244
245 test-trace-empty-line:
246
247
248 68/push _test-trace-stream/imm32
249
250 e8/call clear-trace-stream/disp32
251
252 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
253
254
255 68/push ""/imm32
256 68/push _test-trace-stream/imm32
257
258 e8/call trace/disp32
259
260 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
261
262
263 68/push "F - test-trace-empty-line"/imm32
264 68/push 0/imm32
265
266 b8/copy-to-EAX _test-trace-stream/imm32
267 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 .
268
269 e8/call check-ints-equal/disp32
270
271 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
272
273 c3/return
274
275
276
277
278 _append-3:
279
280 55/push-EBP
281 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
282
283 51/push-ECX
284
285
286 8b/copy 1/mod/*+disp8 5/rm32/EBP . . 0/r32/EAX 0x10/disp8 .
287 8b/copy 0/mod/indirect 0/rm32/EAX . . . 1/r32/ECX . .
288 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX . 1/r32/ECX 4/disp8 .
289 51/push-ECX
290
291 8d/copy-address 1/mod/*+disp8 0/rm32/EAX . . . 1/r32/ECX 4/disp8 .
292 51/push-ECX
293
294 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 .
295
296 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
297
298 e8/call _append-4/disp32
299
300 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32
301 $_append-3:end:
302
303 59/pop-to-ECX
304
305 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
306 5d/pop-to-EBP
307 c3/return
308
309
310 _append-4:
311
312 55/push-EBP
313 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
314
315 51/push-ECX
316 52/push-EDX
317 53/push-EBX
318 56/push-ESI
319 57/push-EDI
320
321 b8/copy-to-EAX 0/imm32
322
323 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 8/disp8 .
324
325 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 2/r32/EDX 0xc/disp8 .
326
327 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 0x10/disp8 .
328
329 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 0x14/disp8 .
330 $_append-4:loop:
331
332 39/compare 3/mod/direct 6/rm32/ESI . . . 1/r32/ECX . .
333 7d/jump-if-greater-or-equal $_append-4:end/disp8
334
335 39/compare 3/mod/direct 7/rm32/EDI . . . 2/r32/EDX . .
336 7d/jump-if-greater-or-equal $_append-4:end/disp8
337
338 8a/copy-byte 0/mod/indirect 6/rm32/ESI . . . 3/r32/BL . .
339 88/copy-byte 0/mod/indirect 7/rm32/EDI . . . 3/r32/BL . .
340
341 40/increment-EAX
342 46/increment-ESI
343 47/increment-EDI
344 eb/jump $_append-4:loop/disp8
345 $_append-4:end:
346
347 5f/pop-to-EDI
348 5e/pop-to-ESI
349 5b/pop-to-EBX
350 5a/pop-to-EDX
351 59/pop-to-ECX
352
353 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
354 5d/pop-to-EBP
355 c3/return
356
357