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 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Heap-size/disp32
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 +-- 9 lines: #? # print("read\n") -----------------------------------------------------------------------------------------------------------------------
121
122
123 51/push-ECX
124 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
125
126 e8/call read-segments/disp32
127
128 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
129 $convert:write:
130 +-- 9 lines: #? # print("write\n") ----------------------------------------------------------------------------------------------------------------------
139
140
141 51/push-ECX
142 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 .
143
144 e8/call write-segments/disp32
145
146 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
147 $convert:end:
148
149 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x5c/imm32
150
151 59/pop-to-ECX
152
153 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
154 5d/pop-to-EBP
155 c3/return
156
157 test-convert:
158
159 55/push-EBP
160 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
161
162
163
164 68/push _test-input-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 b8/copy-to-EAX _test-input-buffered-file/imm32
172 05/add-to-EAX 4/imm32
173 50/push-EAX
174
175 e8/call clear-stream/disp32
176
177 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
178
179
180 68/push _test-output-stream/imm32
181
182 e8/call clear-stream/disp32
183
184 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
185
186
187 b8/copy-to-EAX _test-output-buffered-file/imm32
188 05/add-to-EAX 4/imm32
189 50/push-EAX
190
191 e8/call clear-stream/disp32
192
193 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211 68/push "# comment 1\n"/imm32
212 68/push _test-input-stream/imm32
213
214 e8/call write/disp32
215
216 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
217
218
219 68/push " # comment 2 indented\n"/imm32
220 68/push _test-input-stream/imm32
221
222 e8/call write/disp32
223
224 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
225
226
227 68/push "== code 0x09000000\n"/imm32
228 68/push _test-input-stream/imm32
229
230 e8/call write/disp32
231
232 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
233
234
235 68/push "# comment 3 inside a segment\n"/imm32
236 68/push _test-input-stream/imm32
237
238 e8/call write/disp32
239
240 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
241
242
243 68/push "1\n"/imm32
244 68/push _test-input-stream/imm32
245
246 e8/call write/disp32
247
248 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
249
250
251 68/push "\n"/imm32
252 68/push _test-input-stream/imm32
253
254 e8/call write/disp32
255
256 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
257
258
259 68/push "2 3 # comment 4 inline with other contents\n"/imm32
260 68/push _test-input-stream/imm32
261
262 e8/call write/disp32
263
264 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
265
266
267 68/push "== data 0x0a000000\n"/imm32
268 68/push _test-input-stream/imm32
269
270 e8/call write/disp32
271
272 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
273
274
275 68/push "4 5/imm32\n"/imm32
276 68/push _test-input-stream/imm32
277
278 e8/call write/disp32
279
280 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
281
282
283 68/push "== code\n"/imm32
284 68/push _test-input-stream/imm32
285
286 e8/call write/disp32
287
288 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
289
290
291 68/push "6 7\n"/imm32
292 68/push _test-input-stream/imm32
293
294 e8/call write/disp32
295
296 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
297
298
299 68/push "8 9\n"/imm32
300 68/push _test-input-stream/imm32
301
302 e8/call write/disp32
303
304 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
305
306
307 68/push "== code\n"/imm32
308 68/push _test-input-stream/imm32
309
310 e8/call write/disp32
311
312 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
313
314
315 68/push "10 11\n"/imm32
316 68/push _test-input-stream/imm32
317
318 e8/call write/disp32
319
320 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
321
322
323 68/push _test-output-buffered-file/imm32
324 68/push _test-input-buffered-file/imm32
325
326 e8/call convert/disp32
327
328 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
329
330
331 68/push _test-output-buffered-file/imm32
332
333 e8/call flush/disp32
334
335 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
336
337
338
339
340
341
342
343
344
345 +-- 33 lines: #? # dump output ---------------------------------------------------------------------------------------------------------------------------
378
379
380 68/push "F - test-convert/0"/imm32
381 68/push "== code 0x09000000"/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/1"/imm32
390 68/push "1"/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/2"/imm32
399 68/push "2 3 # comment 4 inline with other contents"/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/3"/imm32
408 68/push "6 7"/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/4"/imm32
417 68/push "8 9"/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/5"/imm32
426 68/push "10 11"/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
434 68/push "F - test-convert/6"/imm32
435 68/push "== data 0x0a000000"/imm32
436 68/push _test-output-stream/imm32
437
438 e8/call check-next-stream-line-equal/disp32
439
440 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
441
442
443 68/push "F - test-convert/7"/imm32
444 68/push "4 5/imm32"/imm32
445 68/push _test-output-stream/imm32
446
447 e8/call check-next-stream-line-equal/disp32
448
449 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
450
451 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
452 5d/pop-to-EBP
453 c3/return
454
455
456 read-segments:
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491 55/push-EBP
492 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
493
494 50/push-EAX
495 51/push-ECX
496 52/push-EDX
497 53/push-EBX
498 56/push-ESI
499
500 81 5/subop/subtract 3/mod/direct 4/rm32/ESP . . . . . 0x200/imm32
501 68/push 0x200/imm32/length
502 68/push 0/imm32/read
503 68/push 0/imm32/write
504 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
505
506 68/push 0/imm32/end
507 68/push 0/imm32/start
508 89/copy 3/mod/direct 2/rm32/EDX . . . 4/r32/ESP . .
509 $read-segments:loop:
510
511
512 51/push-ECX
513
514 e8/call clear-stream/disp32
515
516 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
517
518
519 51/push-ECX
520 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
521
522 e8/call read-line-buffered/disp32
523
524 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
525 $read-segments:check0:
526
527 81 7/subop/compare 0/mod/indirect 1/rm32/ECX . . . . . 0/imm32
528 0f 84/jump-if-equal $read-segments:break/disp32
529 +-- 33 lines: #? # dump line -----------------------------------------------------------------------------------------------------------------------------
562
563
564 52/push-EDX
565 51/push-ECX
566
567 e8/call next-word/disp32
568
569 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
570 $read-segments:check1:
571 +-- 9 lines: #? # print("check1\n") ---------------------------------------------------------------------------------------------------------------------
580
581
582
583 52/push-EDX
584
585 e8/call slice-empty?/disp32
586
587 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
588
589 3d/compare-EAX-and 0/imm32
590 0f 85/jump-if-not-equal $read-segments:loop/disp32
591 $read-segments:check-for-comment:
592 +-- 9 lines: #? # print("check for comment\n") ----------------------------------------------------------------------------------------------------------
601
602
603 8b/copy 0/mod/indirect 2/rm32/EDX . . . 6/r32/ESI . .
604
605 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . .
606 8a/copy-byte 0/mod/indirect 6/rm32/ESI . . . 0/r32/AL . .
607
608 3d/compare-EAX-and 0x23/imm32/hash
609 0f 84/jump-if-equal $read-segments:loop/disp32
610 $read-segments:check-for-segment-header:
611 +-- 9 lines: #? # print("check for segment header\n") ---------------------------------------------------------------------------------------------------
620 +-- 42 lines: #? # dump word-slice -----------------------------------------------------------------------------------------------------------------------
662
663
664
665 68/push "=="/imm32
666 52/push-EDX
667
668 e8/call slice-equal?/disp32
669
670 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
671
672 3d/compare-EAX-and 0/imm32
673 0f 84/jump-if-equal $read-segments:regular-line/disp32
674
675
676 52/push-EDX
677 51/push-ECX
678
679 e8/call next-word/disp32
680
681 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
682 +-- 42 lines: #? # dump segment name ---------------------------------------------------------------------------------------------------------------------
724
725
726 68/push 8/imm32/row-size
727 52/push-EDX
728 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 .
729
730 e8/call leaky-get-or-insert-slice/disp32
731
732 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
733
734 8b/copy 0/mod/indirect 0/rm32/EAX . . . 3/r32/EBX . .
735
736 81 7/subop/compare 3/mod/direct 3/rm32/EBX . . . . . 0/imm32
737 0f 85/jump-if-not-equal $read-segments:loop/disp32
738
739
740 50/push-EAX
741
742
743 68/push 1/imm32
744 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Segment-size/disp32
745 68/push Heap/imm32
746
747 e8/call new-stream/disp32
748
749 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
750
751 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . .
752
753 58/pop-to-EAX
754
755 89/copy 0/mod/indirect 0/rm32/EAX . . . 3/r32/EBX . .
756
757 $read-segments:regular-line:
758 +-- 9 lines: #? # print("regular line\n") ---------------------------------------------------------------------------------------------------------------
767 +-- 33 lines: #? # dump line -----------------------------------------------------------------------------------------------------------------------------
800
801
802 51/push-ECX
803
804 e8/call rewind-stream/disp32
805
806 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
807 +-- 9 lines: #? # print("write stream\n") ---------------------------------------------------------------------------------------------------------------
816
817
818 51/push-ECX
819 53/push-EBX
820
821 e8/call write-stream/disp32
822
823 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
824
825 +-- 9 lines: #? # print("loop\n") -----------------------------------------------------------------------------------------------------------------------
834 e9/jump $read-segments:loop/disp32
835 $read-segments:break:
836 $read-segments:end:
837
838 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x214/imm32
839
840 5e/pop-to-ESI
841 5b/pop-to-EBX
842 5a/pop-to-EDX
843 59/pop-to-ECX
844 58/pop-to-EAX
845
846 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
847 5d/pop-to-EBP
848 c3/return
849
850 write-segments:
851
852
853
854
855
856
857
858
859
860
861 55/push-EBP
862 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
863
864 50/push-EAX
865 52/push-EDX
866 56/push-ESI
867
868 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 0xc/disp8 .
869
870 8b/copy 0/mod/indirect 6/rm32/ESI . . . 2/r32/EDX . .
871
872 81 0/subop/add 3/mod/direct 6/rm32/ESI . . . . . 0xc/imm32
873
874 01/add 3/mod/direct 2/rm32/EDX . . . 6/r32/ESI . .
875 $write-segments:loop:
876
877 39/compare 3/mod/direct 6/rm32/ESI . . . 2/r32/EDX . .
878 73/jump-if-greater-or-equal-unsigned $write-segments:break/disp8
879
880 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 0/r32/EAX 4/disp8 .
881
882
883 50/push-EAX
884 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
885
886 e8/call write-stream-data/disp32
887
888 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
889 $write-segments:continue:
890
891 81 0/subop/add 3/mod/direct 6/rm32/ESI . . . . . 8/imm32
892 eb/jump $write-segments:loop/disp8
893 $write-segments:break:
894
895
896 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
897
898 e8/call flush/disp32
899
900 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
901 $write-segments:end:
902
903 5e/pop-to-ESI
904 5a/pop-to-EDX
905 58/pop-to-EAX
906
907 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
908 5d/pop-to-EBP
909 c3/return
910
911