https://github.com/akkartik/mu/blob/master/079emit.subx
1 == code
2
3
4
5
6
7
8
9
10 emit:
11
12 55/push-ebp
13 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
14
15 50/push-eax
16 56/push-esi
17 57/push-edi
18
19 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0xc/disp8 .
20
21 68/push 0/imm32/end
22 68/push 0/imm32/start
23 89/copy 3/mod/direct 7/rm32/edi . . . 4/r32/esp . .
24
25
26 57/push-edi
27 68/push 0x2f/imm32/slash
28 ff 6/subop/push 1/mod/*+disp8 6/rm32/esi . . . . 4/disp8 .
29 ff 6/subop/push 0/mod/indirect 6/rm32/esi . . . . . .
30
31 e8/call next-token-from-slice/disp32
32
33 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
34
35
36
37 57/push-edi
38
39 e8/call is-valid-name?/disp32
40
41 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
42
43 3d/compare-eax-and 0/imm32/false
44 74/jump-if-equal $emit:hex-int/disp8
45 $emit:name:
46
47
48 56/push-esi
49 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
50
51 e8/call write-slice-buffered/disp32
52
53 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
54
55
56 68/push Space/imm32
57 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
58
59 e8/call write-buffered/disp32
60
61 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
62
63 eb/jump $emit:end/disp8
64
65
66
67
68
69 $emit:hex-int:
70
71
72 57/push-edi
73
74 e8/call parse-hex-int/disp32
75
76 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
77
78
79 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 .
80 50/push-eax
81 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
82
83 e8/call emit-hex/disp32
84
85 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
86 $emit:end:
87
88 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
89
90 5f/pop-to-edi
91 5e/pop-to-esi
92 58/pop-to-eax
93
94 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
95 5d/pop-to-ebp
96 c3/return
97
98 test-emit-number:
99
100 55/push-ebp
101 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
102
103
104
105 68/push _test-output-stream/imm32
106
107 e8/call clear-stream/disp32
108
109 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
110
111
112 68/push $_test-output-buffered-file->buffer/imm32
113
114 e8/call clear-stream/disp32
115
116 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
117
118 b8/copy-to-eax "30"/imm32
119 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
120 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
121 05/add-to-eax 4/imm32
122
123 51/push-ecx
124 50/push-eax
125 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
126
127
128 68/push 1/imm32
129 51/push-ecx
130 68/push _test-output-buffered-file/imm32
131
132 e8/call emit/disp32
133
134 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
135
136
137 68/push _test-output-buffered-file/imm32
138
139 e8/call flush/disp32
140
141 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
142
143
144 68/push "F - test-emit-number/1"/imm32
145 68/push "30 "/imm32
146 68/push _test-output-stream/imm32
147
148 e8/call check-stream-equal/disp32
149
150 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
151
152 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
153 5d/pop-to-ebp
154 c3/return
155
156 test-emit-negative-number:
157
158
159 55/push-ebp
160 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
161
162
163
164 68/push _test-output-stream/imm32
165
166 e8/call clear-stream/disp32
167
168 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
169
170
171 68/push $_test-output-buffered-file->buffer/imm32
172
173 e8/call clear-stream/disp32
174
175 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
176
177 b8/copy-to-eax "-2"/imm32
178 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
179 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
180 05/add-to-eax 4/imm32
181
182 51/push-ecx
183 50/push-eax
184 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
185
186
187 68/push 2/imm32
188 51/push-ecx
189 68/push _test-output-buffered-file/imm32
190
191 e8/call emit/disp32
192
193 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
194
195
196 68/push _test-output-buffered-file/imm32
197
198 e8/call flush/disp32
199
200 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
201
202
203 68/push "F - test-emit-number/1"/imm32
204 68/push "fe ff "/imm32
205 68/push _test-output-stream/imm32
206
207 e8/call check-stream-equal/disp32
208
209 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
210
211 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
212 5d/pop-to-ebp
213 c3/return
214
215 test-emit-number-with-metadata:
216
217 55/push-ebp
218 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
219
220
221
222 68/push _test-output-stream/imm32
223
224 e8/call clear-stream/disp32
225
226 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
227
228
229 68/push $_test-output-buffered-file->buffer/imm32
230
231 e8/call clear-stream/disp32
232
233 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
234
235 b8/copy-to-eax "-2/foo"/imm32
236 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
237 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
238 05/add-to-eax 4/imm32
239
240 51/push-ecx
241 50/push-eax
242 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
243
244
245 68/push 2/imm32
246 51/push-ecx
247 68/push _test-output-buffered-file/imm32
248
249 e8/call emit/disp32
250
251 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
252
253
254 68/push _test-output-buffered-file/imm32
255
256 e8/call flush/disp32
257
258 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
259
260
261
262 68/push "F - test-emit-number-with-metadata"/imm32
263 68/push "fe ff "/imm32
264 68/push _test-output-stream/imm32
265
266 e8/call check-stream-equal/disp32
267
268 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
269
270 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
271 5d/pop-to-ebp
272 c3/return
273
274 test-emit-non-number:
275
276 55/push-ebp
277 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
278
279
280
281 68/push _test-output-stream/imm32
282
283 e8/call clear-stream/disp32
284
285 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
286
287
288 68/push $_test-output-buffered-file->buffer/imm32
289
290 e8/call clear-stream/disp32
291
292 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
293
294 b8/copy-to-eax "xyz"/imm32
295 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
296 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
297 05/add-to-eax 4/imm32
298
299 51/push-ecx
300 50/push-eax
301 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
302
303
304 68/push 2/imm32
305 51/push-ecx
306 68/push _test-output-buffered-file/imm32
307
308 e8/call emit/disp32
309
310 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
311
312
313 68/push _test-output-buffered-file/imm32
314
315 e8/call flush/disp32
316
317 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
318
319
320 68/push "F - test-emit-non-number"/imm32
321 68/push "xyz "/imm32
322 68/push _test-output-stream/imm32
323
324 e8/call check-stream-equal/disp32
325
326 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
327
328 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
329 5d/pop-to-ebp
330 c3/return
331
332 test-emit-non-number-with-metadata:
333
334 55/push-ebp
335 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
336
337
338
339 68/push _test-output-stream/imm32
340
341 e8/call clear-stream/disp32
342
343 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
344
345
346 68/push $_test-output-buffered-file->buffer/imm32
347
348 e8/call clear-stream/disp32
349
350 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
351
352 b8/copy-to-eax "xyz/"/imm32
353 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
354 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
355 05/add-to-eax 4/imm32
356
357 51/push-ecx
358 50/push-eax
359 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
360
361
362 68/push 2/imm32
363 51/push-ecx
364 68/push _test-output-buffered-file/imm32
365
366 e8/call emit/disp32
367
368 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
369
370
371 68/push _test-output-buffered-file/imm32
372
373 e8/call flush/disp32
374
375 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
376
377
378 68/push "F - test-emit-non-number-with-metadata"/imm32
379 68/push "xyz/ "/imm32
380 68/push _test-output-stream/imm32
381
382 e8/call check-stream-equal/disp32
383
384 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
385
386 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
387 5d/pop-to-ebp
388 c3/return
389
390 test-emit-non-number-with-all-hex-digits-and-metadata:
391
392 55/push-ebp
393 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
394
395
396
397 68/push _test-output-stream/imm32
398
399 e8/call clear-stream/disp32
400
401 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
402
403
404 68/push $_test-output-buffered-file->buffer/imm32
405
406 e8/call clear-stream/disp32
407
408 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
409
410 b8/copy-to-eax "abcd/xyz"/imm32
411 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
412 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
413 05/add-to-eax 4/imm32
414
415 51/push-ecx
416 50/push-eax
417 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
418
419
420 68/push 2/imm32
421 51/push-ecx
422 68/push _test-output-buffered-file/imm32
423
424 e8/call emit/disp32
425
426 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
427
428
429 68/push _test-output-buffered-file/imm32
430
431 e8/call flush/disp32
432
433 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
434 +-- 26 lines: #? # dump output ---------------------------------------------------------------------------------------------------------------------------
460
461
462 68/push "F - test-emit-non-number-with-all-hex-digits"/imm32
463 68/push "abcd/xyz "/imm32
464 68/push _test-output-stream/imm32
465
466 e8/call check-stream-equal/disp32
467
468 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
469
470 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
471 5d/pop-to-ebp
472 c3/return