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 $clear-trace-stream:loop:
157
158 39/compare 3/mod/direct 0/rm32/EAX . . . 1/r32/ECX . .
159 7d/jump-if-greater-or-equal $clear-trace-stream:end/disp8
160
161 c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32
162
163 81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 4/imm32
164 eb/jump $clear-trace-stream:loop/disp8
165 $clear-trace-stream:end:
166
167 59/pop-to-ECX
168 58/pop-to-EAX
169
170 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
171 5d/pop-to-EBP
172 c3/return
173
174
175
176 test-trace-single:
177
178
179 68/push _test-trace-stream/imm32
180
181 e8/call clear-trace-stream/disp32
182
183 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
184
185
186 68/push "Ab"/imm32
187 68/push _test-trace-stream/imm32
188
189 e8/call trace/disp32
190
191 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
192
193
194 68/push "F - test-trace-single"/imm32
195 68/push 0x0a6241/imm32/Ab-newline
196
197 b8/copy-to-EAX _test-trace-stream/imm32
198 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 .
199
200 e8/call check-ints-equal/disp32
201
202 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
203
204 c3/return
205
206 test-trace-appends:
207
208
209 68/push _test-trace-stream/imm32
210
211 e8/call clear-trace-stream/disp32
212
213 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
214
215
216 68/push "C"/imm32
217 68/push _test-trace-stream/imm32
218
219 e8/call trace/disp32
220
221 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
222
223
224 68/push "D"/imm32
225 68/push _test-trace-stream/imm32
226
227 e8/call trace/disp32
228
229 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
230
231
232 68/push "F - test-trace-appends"/imm32
233 68/push 0x0a440a43/imm32/C-newline-D-newline
234
235 b8/copy-to-EAX _test-trace-stream/imm32
236 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 .
237
238 e8/call check-ints-equal/disp32
239
240 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
241
242 c3/return
243
244 test-trace-empty-line:
245
246
247 68/push _test-trace-stream/imm32
248
249 e8/call clear-trace-stream/disp32
250
251 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
252
253
254 68/push ""/imm32
255 68/push _test-trace-stream/imm32
256
257 e8/call trace/disp32
258
259 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
260
261
262 68/push "F - test-trace-empty-line"/imm32
263 68/push 0/imm32
264
265 b8/copy-to-EAX _test-trace-stream/imm32
266 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 .
267
268 e8/call check-ints-equal/disp32
269
270 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
271
272 c3/return
273
274
275
276
277 _append-3:
278
279 55/push-EBP
280 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
281
282 51/push-ECX
283
284
285 8b/copy 1/mod/*+disp8 5/rm32/EBP . . 0/r32/EAX 0x10/disp8 .
286 8b/copy 0/mod/indirect 0/rm32/EAX . . . 1/r32/ECX . .
287 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX . 1/r32/ECX 4/disp8 .
288 51/push-ECX
289
290 8d/copy-address 1/mod/*+disp8 0/rm32/EAX . . . 1/r32/ECX 4/disp8 .
291 51/push-ECX
292
293 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 .
294
295 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
296
297 e8/call _append-4/disp32
298
299 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32
300 $_append-3:end:
301
302 59/pop-to-ECX
303
304 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
305 5d/pop-to-EBP
306 c3/return
307
308
309 _append-4:
310
311 55/push-EBP
312 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
313
314 51/push-ECX
315 52/push-EDX
316 53/push-EBX
317 56/push-ESI
318 57/push-EDI
319
320 b8/copy-to-EAX 0/imm32
321
322 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 8/disp8 .
323
324 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 2/r32/EDX 0xc/disp8 .
325
326 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 0x10/disp8 .
327
328 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 0x14/disp8 .
329 $_append-4:loop:
330
331 39/compare 3/mod/direct 6/rm32/ESI . . . 1/r32/ECX . .
332 7d/jump-if-greater-or-equal $_append-4:end/disp8
333
334 39/compare 3/mod/direct 7/rm32/EDI . . . 2/r32/EDX . .
335 7d/jump-if-greater-or-equal $_append-4:end/disp8
336
337 8a/copy-byte 0/mod/indirect 6/rm32/ESI . . . 3/r32/BL . .
338 88/copy-byte 0/mod/indirect 7/rm32/EDI . . . 3/r32/BL . .
339
340 40/increment-EAX
341
342 46/increment-ESI
343
344 47/increment-EDI
345 eb/jump $_append-4:loop/disp8
346 $_append-4:end:
347
348 5f/pop-to-EDI
349 5e/pop-to-ESI
350 5b/pop-to-EBX
351 5a/pop-to-EDX
352 59/pop-to-ECX
353
354 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
355 5d/pop-to-EBP
356 c3/return
357
358