https://github.com/akkartik/mu/blob/master/subx/apps/assort.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 == code
22
23
24
25
26 Entry:
27
28
29
30 68/push Heap/imm32
31 68/push 0x10000/imm32/64KB
32
33 e8/call new-segment/disp32
34
35 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
36
37
38
39 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
40
41
42 81 7/subop/compare 1/mod/*+disp8 5/rm32/EBP . . . . 0/disp8 1/imm32
43 7e/jump-if-lesser-or-equal $run-main/disp8
44
45
46 68/push "test"/imm32
47 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
48
49 e8/call kernel-string-equal?/disp32
50
51 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
52
53 3d/compare-EAX-and 1/imm32
54 75/jump-if-not-equal $run-main/disp8
55
56 e8/call run-tests/disp32
57 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32
58 eb/jump $main:end/disp8
59 $run-main:
60
61
62 81 5/subop/subtract 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
63 89/copy 3/mod/direct 0/rm32/EAX . . . 4/r32/ESP . .
64
65
66 c7 0/subop/copy 0/mod/direct 0/rm32/EAX . . . . . 0/imm32
67
68
69 50/push-EAX/ed
70 68/push Stderr/imm32
71 68/push Stdout/imm32
72 68/push Stdin/imm32
73
74 e8/call convert/disp32
75
76 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32
77
78 bb/copy-to-EBX 0/imm32
79 $main:end:
80 b8/copy-to-EAX 1/imm32/exit
81 cd/syscall 0x80/imm8
82
83
84
85
86
87 convert:
88
89
90
91
92
93
94 55/push-EBP
95 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
96
97 51/push-ECX
98
99 81 5/subop/subtract 3/mod/direct 4/rm32/ESP . . . . . 0x50/imm32
100 68/push 0x50/imm32/length
101 68/push 0/imm32/read
102 68/push 0/imm32/write
103 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
104
105
106 51/push-ECX
107
108 e8/call clear-stream/disp32
109
110 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
111 $convert:read:
112
113
114 51/push-ECX
115 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
116
117 e8/call read-segments/disp32
118
119 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
120 $convert:write:
121
122
123 51/push-ECX
124 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 .
125
126 e8/call write-segments/disp32
127
128 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
129 $convert:end:
130
131 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x5c/imm32
132
133 59/pop-to-ECX
134
135 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
136 5d/pop-to-EBP
137 c3/return
138
139 test-convert:
140
141 55/push-EBP
142 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
143
144
145
146 68/push _test-input-stream/imm32
147
148 e8/call clear-stream/disp32
149
150 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
151
152
153 b8/copy-to-EAX _test-input-buffered-file/imm32
154 05/add-to-EAX 4/imm32
155 50/push-EAX
156
157 e8/call clear-stream/disp32
158
159 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
160
161
162 68/push _test-output-stream/imm32
163
164 e8/call clear-stream/disp32
165
166 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
167
168
169 b8/copy-to-EAX _test-output-buffered-file/imm32
170 05/add-to-EAX 4/imm32
171 50/push-EAX
172
173 e8/call clear-stream/disp32
174
175 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193 68/push "# comment 1\n"/imm32
194 68/push _test-input-stream/imm32
195
196 e8/call write/disp32
197
198 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
199
200
201 68/push " # comment 2 indented\n"/imm32
202 68/push _test-input-stream/imm32
203
204 e8/call write/disp32
205
206 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
207
208
209 68/push "== code 0x09000000\n"/imm32
210 68/push _test-input-stream/imm32
211
212 e8/call write/disp32
213
214 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
215
216
217 68/push "# comment 3 inside a segment\n"/imm32
218 68/push _test-input-stream/imm32
219
220 e8/call write/disp32
221
222 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
223
224
225 68/push "1\n"/imm32
226 68/push _test-input-stream/imm32
227
228 e8/call write/disp32
229
230 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
231
232
233 68/push "\n"/imm32
234 68/push _test-input-stream/imm32
235
236 e8/call write/disp32
237
238 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
239
240
241 68/push "2 3 # comment 4 inline with other contents\n"/imm32
242 68/push _test-input-stream/imm32
243
244 e8/call write/disp32
245
246 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
247
248
249 68/push "== data 0x0a000000\n"/imm32
250 68/push _test-input-stream/imm32
251
252 e8/call write/disp32
253
254 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
255
256
257 68/push "4 5/imm32\n"/imm32
258 68/push _test-input-stream/imm32
259
260 e8/call write/disp32
261
262 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
263
264
265 68/push "== code\n"/imm32
266 68/push _test-input-stream/imm32
267
268 e8/call write/disp32
269
270 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
271
272
273 68/push "6 7\n"/imm32
274 68/push _test-input-stream/imm32
275
276 e8/call write/disp32
277
278 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
279
280
281 68/push "8 9\n"/imm32
282 68/push _test-input-stream/imm32
283
284 e8/call write/disp32
285
286 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
287
288
289 68/push "== code\n"/imm32
290 68/push _test-input-stream/imm32
291
292 e8/call write/disp32
293
294 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
295
296
297 68/push "10 11\n"/imm32
298 68/push _test-input-stream/imm32
299
300 e8/call write/disp32
301
302 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
303
304
305 68/push _test-output-buffered-file/imm32
306 68/push _test-input-buffered-file/imm32
307
308 e8/call convert/disp32
309
310 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/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
321
322
323
324
325
326
327 +-- 33 lines: #? # dump output ---------------------------------------------------------------------------------------------------------------------------
360
361
362 68/push "F - test-convert/0"/imm32
363 68/push "== code 0x09000000"/imm32
364 68/push _test-output-stream/imm32
365
366 e8/call check-next-stream-line-equal/disp32
367
368 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
369
370
371 68/push "F - test-convert/1"/imm32
372 68/push "1"/imm32
373 68/push _test-output-stream/imm32
374
375 e8/call check-next-stream-line-equal/disp32
376
377 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
378
379
380 68/push "F - test-convert/2"/imm32
381 68/push "2 3 # comment 4 inline with other contents"/imm32
382 68/push _test-output-stream/imm32
383
384 e8/call check-next-stream-line-equal/disp32
385
386 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
387
388
389 68/push "F - test-convert/3"/imm32
390 68/push "6 7"/imm32
391 68/push _test-output-stream/imm32
392
393 e8/call check-next-stream-line-equal/disp32
394
395 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
396
397
398 68/push "F - test-convert/4"/imm32
399 68/push "8 9"/imm32
400 68/push _test-output-stream/imm32
401
402 e8/call check-next-stream-line-equal/disp32
403
404 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
405
406
407 68/push "F - test-convert/5"/imm32
408 68/push "10 11"/imm32
409 68/push _test-output-stream/imm32
410
411 e8/call check-next-stream-line-equal/disp32
412
413 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
414
415
416 68/push "F - test-convert/6"/imm32
417 68/push "== data 0x0a000000"/imm32
418 68/push _test-output-stream/imm32
419
420 e8/call check-next-stream-line-equal/disp32
421
422 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
423
424
425 68/push "F - test-convert/7"/imm32
426 68/push "4 5/imm32"/imm32
427 68/push _test-output-stream/imm32
428
429 e8/call check-next-stream-line-equal/disp32
430
431 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
432
433 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
434 5d/pop-to-EBP
435 c3/return
436
437
438 read-segments:
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473 55/push-EBP
474 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
475
476 50/push-EAX
477 51/push-ECX
478 52/push-EDX
479 53/push-EBX
480 56/push-ESI
481
482 81 5/subop/subtract 3/mod/direct 4/rm32/ESP . . . . . 0x200/imm32
483 68/push 0x200/imm32/length
484 68/push 0/imm32/read
485 68/push 0/imm32/write
486 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
487
488 68/push 0/imm32/end
489 68/push 0/imm32/start
490 89/copy 3/mod/direct 2/rm32/EDX . . . 4/r32/ESP . .
491 $read-segments:loop:
492
493
494 51/push-ECX
495
496 e8/call clear-stream/disp32
497
498 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
499
500
501 51/push-ECX
502 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
503
504 e8/call read-line-buffered/disp32
505
506 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
507 $read-segments:check0:
508
509 81 7/subop/compare 0/mod/indirect 1/rm32/ECX . . . . . 0/imm32
510 0f 84/jump-if-equal $read-segments:break/disp32
511 +-- 26 lines: #? # dump line -----------------------------------------------------------------------------------------------------------------------------
537
538
539 52/push-EDX
540 51/push-ECX
541
542 e8/call next-word/disp32
543
544 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
545 $read-segments:check1:
546
547
548
549 52/push-EDX
550
551 e8/call slice-empty?/disp32
552
553 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
554
555 3d/compare-EAX-and 0/imm32
556 0f 85/jump-if-not-equal $read-segments:loop/disp32
557 $read-segments:check-for-comment:
558
559
560 8b/copy 0/mod/indirect 2/rm32/EDX . . . 6/r32/ESI . .
561
562 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . .
563 8a/copy-byte 0/mod/indirect 6/rm32/ESI . . . 0/r32/AL . .
564
565 3d/compare-EAX-and 0x23/imm32/hash
566 0f 84/jump-if-equal $read-segments:loop/disp32
567 $read-segments:check-for-segment-header:
568 +-- 42 lines: #? # dump word-slice -----------------------------------------------------------------------------------------------------------------------
610
611
612
613 68/push "=="/imm32
614 52/push-EDX
615
616 e8/call slice-equal?/disp32
617
618 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
619
620 3d/compare-EAX-and 0/imm32
621 0f 84/jump-if-equal $read-segments:regular-line/disp32
622
623
624 52/push-EDX
625 51/push-ECX
626
627 e8/call next-word/disp32
628
629 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
630 +-- 42 lines: #? # dump segment name ---------------------------------------------------------------------------------------------------------------------
672
673
674 68/push 8/imm32/row-size
675 52/push-EDX
676 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 .
677
678 e8/call leaky-get-or-insert-slice/disp32
679
680 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
681
682 8b/copy 0/mod/indirect 0/rm32/EAX . . . 3/r32/EBX . .
683
684 81 7/subop/compare 3/mod/direct 3/rm32/EBX . . . . . 0/imm32
685 0f 85/jump-if-not-equal $read-segments:loop/disp32
686
687
688 50/push-EAX
689
690
691 68/push 1/imm32
692 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Segment-size/disp32
693 68/push Heap/imm32
694
695 e8/call new-stream/disp32
696
697 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
698
699 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . .
700
701 58/pop-to-EAX
702
703 89/copy 0/mod/indirect 0/rm32/EAX . . . 3/r32/EBX . .
704
705 $read-segments:regular-line:
706
707
708 51/push-ECX
709
710 e8/call rewind-stream/disp32
711
712 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
713
714
715 51/push-ECX
716 53/push-EBX
717
718 e8/call write-stream/disp32
719
720 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
721
722 e9/jump $read-segments:loop/disp32
723 $read-segments:break:
724 $read-segments:end:
725
726 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x214/imm32
727
728 5e/pop-to-ESI
729 5b/pop-to-EBX
730 5a/pop-to-EDX
731 59/pop-to-ECX
732 58/pop-to-EAX
733
734 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
735 5d/pop-to-EBP
736 c3/return
737
738 write-segments:
739
740
741
742
743
744
745
746
747
748
749 55/push-EBP
750 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
751
752 50/push-EAX
753 52/push-EDX
754 56/push-ESI
755
756 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 0xc/disp8 .
757
758 8b/copy 0/mod/indirect 6/rm32/ESI . . . 2/r32/EDX . .
759
760 81 0/subop/add 3/mod/direct 6/rm32/ESI . . . . . 0xc/imm32
761
762 01/add 3/mod/direct 2/rm32/EDX . . . 6/r32/ESI . .
763 $write-segments:loop:
764
765 39/compare 3/mod/direct 6/rm32/ESI . . . 2/r32/EDX . .
766 73/jump-if-greater-or-equal-unsigned $write-segments:break/disp8
767
768 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 0/r32/EAX 4/disp8 .
769
770
771 50/push-EAX
772 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
773
774 e8/call write-stream-data/disp32
775
776 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
777 $write-segments:continue:
778
779 81 0/subop/add 3/mod/direct 6/rm32/ESI . . . . . 8/imm32
780 eb/jump $write-segments:loop/disp8
781 $write-segments:break:
782
783
784 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
785
786 e8/call flush/disp32
787
788 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
789 $write-segments:end:
790
791 5e/pop-to-ESI
792 5a/pop-to-EDX
793 58/pop-to-EAX
794
795 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
796 5d/pop-to-EBP
797 c3/return
798
799 == data
800
801 Segment-size:
802 0x1000/imm32/4KB
803
804