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