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
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 b8/copy-to-eax _test-output-buffered-file/imm32
113 05/add-to-eax 4/imm32
114 50/push-eax
115
116 e8/call clear-stream/disp32
117
118 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
119
120 b8/copy-to-eax "30"/imm32
121 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
122 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
123 05/add-to-eax 4/imm32
124
125 51/push-ecx
126 50/push-eax
127 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
128
129
130 68/push 1/imm32
131 51/push-ecx
132 68/push _test-output-buffered-file/imm32
133
134 e8/call emit/disp32
135
136 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
137
138
139 68/push _test-output-buffered-file/imm32
140
141 e8/call flush/disp32
142
143 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
144
145
146 68/push "F - test-emit-number/1"/imm32
147 68/push "30 "/imm32
148 68/push _test-output-stream/imm32
149
150 e8/call check-stream-equal/disp32
151
152 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
153
154 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
155 5d/pop-to-ebp
156 c3/return
157
158 test-emit-negative-number:
159
160
161 55/push-ebp
162 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
163
164
165
166 68/push _test-output-stream/imm32
167
168 e8/call clear-stream/disp32
169
170 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
171
172
173 b8/copy-to-eax _test-output-buffered-file/imm32
174 05/add-to-eax 4/imm32
175 50/push-eax
176
177 e8/call clear-stream/disp32
178
179 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
180
181 b8/copy-to-eax "-2"/imm32
182 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
183 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
184 05/add-to-eax 4/imm32
185
186 51/push-ecx
187 50/push-eax
188 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
189
190
191 68/push 2/imm32
192 51/push-ecx
193 68/push _test-output-buffered-file/imm32
194
195 e8/call emit/disp32
196
197 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
198
199
200 68/push _test-output-buffered-file/imm32
201
202 e8/call flush/disp32
203
204 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
205
206
207 68/push "F - test-emit-number/1"/imm32
208 68/push "fe ff "/imm32
209 68/push _test-output-stream/imm32
210
211 e8/call check-stream-equal/disp32
212
213 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
214
215 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
216 5d/pop-to-ebp
217 c3/return
218
219 test-emit-number-with-metadata:
220
221 55/push-ebp
222 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
223
224
225
226 68/push _test-output-stream/imm32
227
228 e8/call clear-stream/disp32
229
230 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
231
232
233 b8/copy-to-eax _test-output-buffered-file/imm32
234 05/add-to-eax 4/imm32
235 50/push-eax
236
237 e8/call clear-stream/disp32
238
239 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
240
241 b8/copy-to-eax "-2/foo"/imm32
242 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
243 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
244 05/add-to-eax 4/imm32
245
246 51/push-ecx
247 50/push-eax
248 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
249
250
251 68/push 2/imm32
252 51/push-ecx
253 68/push _test-output-buffered-file/imm32
254
255 e8/call emit/disp32
256
257 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
258
259
260 68/push _test-output-buffered-file/imm32
261
262 e8/call flush/disp32
263
264 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
265
266
267
268 68/push "F - test-emit-number-with-metadata"/imm32
269 68/push "fe ff "/imm32
270 68/push _test-output-stream/imm32
271
272 e8/call check-stream-equal/disp32
273
274 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
275
276 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
277 5d/pop-to-ebp
278 c3/return
279
280 test-emit-non-number:
281
282 55/push-ebp
283 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
284
285
286
287 68/push _test-output-stream/imm32
288
289 e8/call clear-stream/disp32
290
291 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
292
293
294 b8/copy-to-eax _test-output-buffered-file/imm32
295 05/add-to-eax 4/imm32
296 50/push-eax
297
298 e8/call clear-stream/disp32
299
300 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
301
302 b8/copy-to-eax "xyz"/imm32
303 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
304 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
305 05/add-to-eax 4/imm32
306
307 51/push-ecx
308 50/push-eax
309 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
310
311
312 68/push 2/imm32
313 51/push-ecx
314 68/push _test-output-buffered-file/imm32
315
316 e8/call emit/disp32
317
318 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
319
320
321 68/push _test-output-buffered-file/imm32
322
323 e8/call flush/disp32
324
325 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
326
327
328 68/push "F - test-emit-non-number"/imm32
329 68/push "xyz "/imm32
330 68/push _test-output-stream/imm32
331
332 e8/call check-stream-equal/disp32
333
334 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
335
336 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
337 5d/pop-to-ebp
338 c3/return
339
340 test-emit-non-number-with-metadata:
341
342 55/push-ebp
343 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
344
345
346
347 68/push _test-output-stream/imm32
348
349 e8/call clear-stream/disp32
350
351 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
352
353
354 b8/copy-to-eax _test-output-buffered-file/imm32
355 05/add-to-eax 4/imm32
356 50/push-eax
357
358 e8/call clear-stream/disp32
359
360 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
361
362 b8/copy-to-eax "xyz/"/imm32
363 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
364 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
365 05/add-to-eax 4/imm32
366
367 51/push-ecx
368 50/push-eax
369 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
370
371
372 68/push 2/imm32
373 51/push-ecx
374 68/push _test-output-buffered-file/imm32
375
376 e8/call emit/disp32
377
378 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
379
380
381 68/push _test-output-buffered-file/imm32
382
383 e8/call flush/disp32
384
385 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
386
387
388 68/push "F - test-emit-non-number-with-metadata"/imm32
389 68/push "xyz/ "/imm32
390 68/push _test-output-stream/imm32
391
392 e8/call check-stream-equal/disp32
393
394 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
395
396 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
397 5d/pop-to-ebp
398 c3/return
399
400 test-emit-non-number-with-all-hex-digits-and-metadata:
401
402 55/push-ebp
403 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
404
405
406
407 68/push _test-output-stream/imm32
408
409 e8/call clear-stream/disp32
410
411 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
412
413
414 b8/copy-to-eax _test-output-buffered-file/imm32
415 05/add-to-eax 4/imm32
416 50/push-eax
417
418 e8/call clear-stream/disp32
419
420 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
421
422 b8/copy-to-eax "abcd/xyz"/imm32
423 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
424 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
425 05/add-to-eax 4/imm32
426
427 51/push-ecx
428 50/push-eax
429 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
430
431
432 68/push 2/imm32
433 51/push-ecx
434 68/push _test-output-buffered-file/imm32
435
436 e8/call emit/disp32
437
438 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
439
440
441 68/push _test-output-buffered-file/imm32
442
443 e8/call flush/disp32
444
445 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
446 +-- 26 lines: #? # dump output ---------------------------------------------------------------------------------------------------------------------------
472
473
474 68/push "F - test-emit-non-number-with-all-hex-digits"/imm32
475 68/push "abcd/xyz "/imm32
476 68/push _test-output-stream/imm32
477
478 e8/call check-stream-equal/disp32
479
480 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
481
482 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
483 5d/pop-to-ebp
484 c3/return