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