https://github.com/akkartik/mu/blob/master/subx/apps/pack.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 == code
19
20
21
22
23
24
25
26
27
28
29
30 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
31
32
33 81 7/subop/compare 1/mod/*+disp8 5/rm32/EBP . . . . 0/disp8 1/imm32
34 7e/jump-if-lesser-or-equal $run-main/disp8
35
36
37 68/push "test"/imm32
38 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
39
40 e8/call kernel-string-equal/disp32
41
42 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
43
44 3d/compare-EAX 1/imm32
45 75/jump-if-not-equal $run-main/disp8
46
47 e8/call run-tests/disp32
48 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32
49 eb/jump $main:end/disp8
50 $run-main:
51
52
53 81 5/subop/subtract 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
54 89/copy 3/mod/direct 0/rm32/EAX . . . 4/r32/ESP . .
55
56
57 c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32
58
59
60 50/push-EAX/ed
61 68/push Stderr/imm32
62 68/push Stdout/imm32
63 68/push Stdin/imm32
64
65 e8/call convert/disp32
66
67 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32
68
69 bb/copy-to-EBX 0/imm32
70 $main:end:
71 b8/copy-to-EAX 1/imm32/exit
72 cd/syscall 0x80/imm8
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134 convert:
135
136
137
138
139
140
141
142
143
144
145 55/push-EBP
146 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
147
148
149
150 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
151 5d/pop-to-EBP
152 c3/return
153
154
155 next-word:
156
157 55/push-EBP
158 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
159
160 50/push-EAX
161 51/push-ECX
162 56/push-ESI
163 57/push-EDI
164
165 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 8/disp8 .
166
167 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 0xc/disp8 .
168
169
170 68/push 0x20/imm32/space
171 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
172
173 e8/call skip-chars-matching/disp32
174
175 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
176
177 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
178 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/EAX 0xc/disp8 .
179 89/copy 0/mod/indirect 7/rm32/EDI . . . 0/r32/EAX . .
180
181
182 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . .
183 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/AL 0xc/disp8 .
184
185 3d/compare-EAX-with 0x23/imm32/pound
186 75/jump-if-not-equal $next-word:not-comment/disp8
187
188 8b/copy 0/mod/indirect 6/rm32/ESI . . . 0/r32/EAX . .
189 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 0/index/EAX . 0/r32/EAX 0xc/disp8 .
190 89/copy 1/mod/*+disp8 7/rm32/EDI . . . 0/r32/EAX 4/disp8 .
191
192 89/copy 1/mod/*+disp8 6/rm32/ESI . . . 0/r32/EAX 4/disp8 .
193
194 eb/jump $next-word:end/disp8
195 $next-word:not-comment:
196
197
198 68/push 0x20/imm32/space
199 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
200
201 e8/call skip-chars-not-matching/disp32
202
203 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
204
205 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
206 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/EAX 0xc/disp8 .
207 89/copy 1/mod/*+disp8 7/rm32/EDI . . . 0/r32/EAX 4/disp8 .
208 $next-word:end:
209
210 5f/pop-to-EDI
211 5e/pop-to-ESI
212 59/pop-to-ECX
213 58/pop-to-EAX
214
215 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
216 5d/pop-to-EBP
217 c3/return
218
219 test-next-word:
220
221 55/push-EBP
222 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
223
224
225
226 68/push _test-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 68/push 0/imm32/end
233 68/push 0/imm32/start
234 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
235
236
237 68/push " ab"/imm32
238 68/push _test-stream/imm32
239
240 e8/call write/disp32
241
242 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
243
244
245 51/push-ECX
246 68/push _test-stream/imm32
247
248 e8/call next-word/disp32
249
250 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
251
252
253
254 68/push "F - test-next-word: start"/imm32
255 68/push 0xe/imm32
256
257 8b/copy 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . .
258 81 5/subop/subtract 3/mod/direct 0/rm32/EAX . . . . . _test-stream/imm32
259 50/push-EAX
260
261 e8/call check-ints-equal/disp32
262
263 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
264
265
266
267 68/push "F - test-next-word: end"/imm32
268 68/push 0x10/imm32
269
270 8b/copy 1/mod/*+disp8 1/rm32/ECX . . . 0/r32/EAX 4/disp8 .
271 81 5/subop/subtract 3/mod/direct 0/rm32/EAX . . . . . _test-stream/imm32
272 50/push-EAX
273
274 e8/call check-ints-equal/disp32
275
276 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
277
278 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
279 5d/pop-to-EBP
280 c3/return
281
282 test-next-word-returns-whole-comment:
283
284 55/push-EBP
285 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
286
287
288
289 68/push _test-stream/imm32
290
291 e8/call clear-stream/disp32
292
293 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
294
295 68/push 0/imm32/end
296 68/push 0/imm32/start
297 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
298
299
300 68/push " # a"/imm32
301 68/push _test-stream/imm32
302
303 e8/call write/disp32
304
305 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
306
307
308 51/push-ECX
309 68/push _test-stream/imm32
310
311 e8/call next-word/disp32
312
313 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
314
315
316
317 68/push "F - test-next-word-returns-whole-comment: start"/imm32
318 68/push 0xe/imm32
319
320 8b/copy 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . .
321 81 5/subop/subtract 3/mod/direct 0/rm32/EAX . . . . . _test-stream/imm32
322 50/push-EAX
323
324 e8/call check-ints-equal/disp32
325
326 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
327
328
329
330 68/push "F - test-next-word-returns-whole-comment: end"/imm32
331 68/push 0x11/imm32
332
333 8b/copy 1/mod/*+disp8 1/rm32/ECX . . . 0/r32/EAX 4/disp8 .
334 81 5/subop/subtract 3/mod/direct 0/rm32/EAX . . . . . _test-stream/imm32
335 50/push-EAX
336
337 e8/call check-ints-equal/disp32
338
339 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
340
341 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
342 5d/pop-to-EBP
343 c3/return
344
345
346 emit-hex:
347
348 55/push-EBP
349 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
350
351 50/push-EAX
352 51/push-ECX
353 52/push-EDX
354 53/push-EBX
355 57/push-EDI
356
357 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 8/disp8 .
358
359 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 3/r32/EBX 0xc/disp8 .
360
361 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 2/r32/EDX 0x10/disp8 .
362
363 31/xor 3/mod/direct 1/rm32/ECX . . . 1/r32/ECX . .
364 $emit-hex:loop:
365
366 39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . .
367 7d/jump-if-greater-or-equal $emit-hex:end/disp8
368
369
370 53/push-EBX
371 57/push-EDI
372
373 e8/call print-byte/disp32
374
375 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
376
377
378 68/push 0x20/imm32/space
379 57/push-EDI
380
381 e8/call write-byte/disp32
382
383 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
384
385 c1/shift 5/subop/logic-right 3/mod/direct 3/rm32/EBX . . . . . 8/imm8
386
387 41/increment-ECX
388 eb/jump $emit-hex:loop/disp8
389 $emit-hex:end:
390
391 5f/pop-to-EDI
392 5b/pop-to-EBX
393 5a/pop-to-EAX
394 59/pop-to-ECX
395 58/pop-to-EAX
396
397 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
398 5d/pop-to-EBP
399 c3/return
400
401 test-emit-hex-single-byte:
402
403
404
405 68/push _test-stream/imm32
406
407 e8/call clear-stream/disp32
408
409 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
410
411
412 b8/copy-to-EAX _test-buffered-file/imm32
413 05/add-to-EAX 4/imm32
414 50/push-EAX
415
416 e8/call clear-stream/disp32
417
418 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
419
420
421 68/push 1/imm32
422 68/push 0xab/imm32
423 68/push _test-buffered-file/imm32
424
425 e8/call emit-hex/disp32
426
427 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
428
429
430 68/push _test-buffered-file/imm32
431
432 e8/call flush/disp32
433
434 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
435
436
437 68/push "F - test-emit-hex-single-byte"/imm32
438 68/push 0x206261/imm32
439
440 b8/copy-to-EAX _test-stream/imm32
441 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 .
442
443 e8/call check-ints-equal/disp32
444
445 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
446
447 c3/return
448
449 test-emit-hex-multiple-byte:
450
451
452
453 68/push _test-stream/imm32
454
455 e8/call clear-stream/disp32
456
457 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
458
459
460 b8/copy-to-EAX _test-buffered-file/imm32
461 05/add-to-EAX 4/imm32
462 50/push-EAX
463
464 e8/call clear-stream/disp32
465
466 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
467
468
469 68/push 2/imm32
470 68/push 0x1234/imm32
471 68/push _test-buffered-file/imm32
472
473 e8/call emit-hex/disp32
474
475 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
476
477
478 68/push _test-buffered-file/imm32
479
480 e8/call flush/disp32
481
482 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
483
484
485
486 68/push "F - test-emit-hex-multiple-byte/1"/imm32
487 68/push 0x31203433/imm32
488
489 b8/copy-to-EAX _test-stream/imm32
490 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 .
491
492 e8/call check-ints-equal/disp32
493
494 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
495
496
497 68/push "F - test-emit-hex-multiple-byte/2"/imm32
498 68/push 0x2032/imm32
499
500 b8/copy-to-EAX _test-stream/imm32
501 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0x10/disp8 .
502
503 e8/call check-ints-equal/disp32
504
505 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
506
507 c3/return
508
509 c3/return
510
511 test-emit-hex-zero-pad:
512
513
514
515 68/push _test-stream/imm32
516
517 e8/call clear-stream/disp32
518
519 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
520
521
522 b8/copy-to-EAX _test-buffered-file/imm32
523 05/add-to-EAX 4/imm32
524 50/push-EAX
525
526 e8/call clear-stream/disp32
527
528 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
529
530
531 68/push 2/imm32
532 68/push 0xab/imm32
533 68/push _test-buffered-file/imm32
534
535 e8/call emit-hex/disp32
536
537 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
538
539
540 68/push _test-buffered-file/imm32
541
542 e8/call flush/disp32
543
544 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
545
546
547
548 68/push "F - test-emit-hex-zero-pad/1"/imm32
549 68/push 0x30206261/imm32
550
551 b8/copy-to-EAX _test-stream/imm32
552 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 .
553
554 e8/call check-ints-equal/disp32
555
556 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
557
558
559 68/push "F - test-emit-hex-zero-pad/2"/imm32
560 68/push 0x2030/imm32
561
562 b8/copy-to-EAX _test-stream/imm32
563 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0x10/disp8 .
564
565 e8/call check-ints-equal/disp32
566
567 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
568
569 c3/return
570
571