https://github.com/akkartik/mu/blob/master/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 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
29
30
31
32
33 68/push Heap/imm32
34 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Heap-size/disp32
35
36 e8/call new-segment/disp32
37
38 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
39
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
47 68/push "test"/imm32
48 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
49
50 e8/call kernel-string-equal?/disp32
51
52 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
53
54 3d/compare-eax-and 0/imm32
55 74/jump-if-equal $run-main/disp8
56
57 e8/call run-tests/disp32
58
59 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32
60 eb/jump $main:end/disp8
61 $run-main:
62
63
64 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 8/imm32
65 89/copy 3/mod/direct 0/rm32/eax . . . 4/r32/esp . .
66
67
68 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32
69
70
71 50/push-eax/ed
72 68/push Stderr/imm32
73 68/push Stdout/imm32
74 68/push Stdin/imm32
75
76 e8/call convert/disp32
77
78 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
79
80 bb/copy-to-ebx 0/imm32
81 $main:end:
82 b8/copy-to-eax 1/imm32/exit
83 cd/syscall 0x80/imm8
84
85
86
87
88
89 convert:
90
91
92
93
94
95
96 55/push-ebp
97 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
98
99 51/push-ecx
100
101 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0x50/imm32
102 68/push 0x50/imm32/length
103 68/push 0/imm32/read
104 68/push 0/imm32/write
105 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
106
107
108 51/push-ecx
109
110 e8/call clear-stream/disp32
111
112 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
113 $convert:read:
114 +-- 9 lines: #? # print("read\n") -----------------------------------------------------------------------------------------------------------------------
123
124
125 51/push-ecx
126 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
127
128 e8/call read-segments/disp32
129
130 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
131 $convert:write:
132 +-- 9 lines: #? # print("write\n") ----------------------------------------------------------------------------------------------------------------------
141
142
143 51/push-ecx
144 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
145
146 e8/call write-segments/disp32
147
148 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
149 $convert:end:
150
151 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x5c/imm32
152
153 59/pop-to-ecx
154
155 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
156 5d/pop-to-ebp
157 c3/return
158
159 test-convert:
160
161 55/push-ebp
162 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
163
164
165
166 68/push _test-input-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-input-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
182 68/push _test-output-stream/imm32
183
184 e8/call clear-stream/disp32
185
186 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
187
188
189 b8/copy-to-eax _test-output-buffered-file/imm32
190 05/add-to-eax 4/imm32
191 50/push-eax
192
193 e8/call clear-stream/disp32
194
195 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213 68/push "# comment 1\n"/imm32
214 68/push _test-input-stream/imm32
215
216 e8/call write/disp32
217
218 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
219
220
221 68/push " # comment 2 indented\n"/imm32
222 68/push _test-input-stream/imm32
223
224 e8/call write/disp32
225
226 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
227
228
229 68/push "== code 0x09000000\n"/imm32
230 68/push _test-input-stream/imm32
231
232 e8/call write/disp32
233
234 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
235
236
237 68/push "# comment 3 inside a segment\n"/imm32
238 68/push _test-input-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 68/push "1\n"/imm32
246 68/push _test-input-stream/imm32
247
248 e8/call write/disp32
249
250 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
251
252
253 68/push "\n"/imm32
254 68/push _test-input-stream/imm32
255
256 e8/call write/disp32
257
258 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
259
260
261 68/push "2 3 # comment 4 inline with other contents\n"/imm32
262 68/push _test-input-stream/imm32
263
264 e8/call write/disp32
265
266 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
267
268
269 68/push "== data 0x0a000000\n"/imm32
270 68/push _test-input-stream/imm32
271
272 e8/call write/disp32
273
274 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
275
276
277 68/push "4 5/imm32\n"/imm32
278 68/push _test-input-stream/imm32
279
280 e8/call write/disp32
281
282 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
283
284
285 68/push "== code\n"/imm32
286 68/push _test-input-stream/imm32
287
288 e8/call write/disp32
289
290 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
291
292
293 68/push "6 7\n"/imm32
294 68/push _test-input-stream/imm32
295
296 e8/call write/disp32
297
298 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
299
300
301 68/push "8 9\n"/imm32
302 68/push _test-input-stream/imm32
303
304 e8/call write/disp32
305
306 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
307
308
309 68/push "== code\n"/imm32
310 68/push _test-input-stream/imm32
311
312 e8/call write/disp32
313
314 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
315
316
317 68/push "10 11\n"/imm32
318 68/push _test-input-stream/imm32
319
320 e8/call write/disp32
321
322 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
323
324
325 68/push _test-output-buffered-file/imm32
326 68/push _test-input-buffered-file/imm32
327
328 e8/call convert/disp32
329
330 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
331
332
333 68/push _test-output-buffered-file/imm32
334
335 e8/call flush/disp32
336
337 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
338
339
340
341
342
343
344
345
346
347 +-- 33 lines: #? # dump output ---------------------------------------------------------------------------------------------------------------------------
380
381
382 68/push "F - test-convert/0"/imm32
383 68/push "== code 0x09000000"/imm32
384 68/push _test-output-stream/imm32
385
386 e8/call check-next-stream-line-equal/disp32
387
388 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
389
390
391 68/push "F - test-convert/1"/imm32
392 68/push "1"/imm32
393 68/push _test-output-stream/imm32
394
395 e8/call check-next-stream-line-equal/disp32
396
397 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
398
399
400 68/push "F - test-convert/2"/imm32
401 68/push "2 3 # comment 4 inline with other contents"/imm32
402 68/push _test-output-stream/imm32
403
404 e8/call check-next-stream-line-equal/disp32
405
406 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
407
408
409 68/push "F - test-convert/3"/imm32
410 68/push "6 7"/imm32
411 68/push _test-output-stream/imm32
412
413 e8/call check-next-stream-line-equal/disp32
414
415 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
416
417
418 68/push "F - test-convert/4"/imm32
419 68/push "8 9"/imm32
420 68/push _test-output-stream/imm32
421
422 e8/call check-next-stream-line-equal/disp32
423
424 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
425
426
427 68/push "F - test-convert/5"/imm32
428 68/push "10 11"/imm32
429 68/push _test-output-stream/imm32
430
431 e8/call check-next-stream-line-equal/disp32
432
433 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
434
435
436 68/push "F - test-convert/6"/imm32
437 68/push "== data 0x0a000000"/imm32
438 68/push _test-output-stream/imm32
439
440 e8/call check-next-stream-line-equal/disp32
441
442 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
443
444
445 68/push "F - test-convert/7"/imm32
446 68/push "4 5/imm32"/imm32
447 68/push _test-output-stream/imm32
448
449 e8/call check-next-stream-line-equal/disp32
450
451 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
452
453 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
454 5d/pop-to-ebp
455 c3/return
456
457
458 read-segments:
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
492
493 55/push-ebp
494 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
495
496 50/push-eax
497 51/push-ecx
498 52/push-edx
499 53/push-ebx
500 56/push-esi
501
502 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0x200/imm32
503 68/push 0x200/imm32/length
504 68/push 0/imm32/read
505 68/push 0/imm32/write
506 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
507
508 68/push 0/imm32/end
509 68/push 0/imm32/start
510 89/copy 3/mod/direct 2/rm32/edx . . . 4/r32/esp . .
511 $read-segments:loop:
512
513
514 51/push-ecx
515
516 e8/call clear-stream/disp32
517
518 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
519
520
521 51/push-ecx
522 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
523
524 e8/call read-line-buffered/disp32
525
526 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
527 $read-segments:check0:
528
529 81 7/subop/compare 0/mod/indirect 1/rm32/ecx . . . . . 0/imm32
530 0f 84/jump-if-equal $read-segments:break/disp32
531 +-- 33 lines: #? # dump line -----------------------------------------------------------------------------------------------------------------------------
564
565
566 52/push-edx
567 51/push-ecx
568
569 e8/call next-word/disp32
570
571 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
572 $read-segments:check1:
573 +-- 9 lines: #? # print("check1\n") ---------------------------------------------------------------------------------------------------------------------
582
583
584
585 52/push-edx
586
587 e8/call slice-empty?/disp32
588
589 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
590
591 3d/compare-eax-and 0/imm32
592 0f 85/jump-if-not-equal $read-segments:loop/disp32
593 $read-segments:check-for-comment:
594 +-- 9 lines: #? # print("check for comment\n") ----------------------------------------------------------------------------------------------------------
603
604
605 8b/copy 0/mod/indirect 2/rm32/edx . . . 6/r32/esi . .
606
607 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . .
608 8a/copy-byte 0/mod/indirect 6/rm32/esi . . . 0/r32/AL . .
609
610 3d/compare-eax-and 0x23/imm32/hash
611 0f 84/jump-if-equal $read-segments:loop/disp32
612 $read-segments:check-for-segment-header:
613 +-- 9 lines: #? # print("check for segment header\n") ---------------------------------------------------------------------------------------------------
622 +-- 42 lines: #? # dump word-slice -----------------------------------------------------------------------------------------------------------------------
664
665
666
667 68/push "=="/imm32
668 52/push-edx
669
670 e8/call slice-equal?/disp32
671
672 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
673
674 3d/compare-eax-and 0/imm32
675 0f 84/jump-if-equal $read-segments:regular-line/disp32
676
677
678 52/push-edx
679 51/push-ecx
680
681 e8/call next-word/disp32
682
683 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
684 +-- 42 lines: #? # dump segment name ---------------------------------------------------------------------------------------------------------------------
726
727
728 68/push 8/imm32/row-size
729 52/push-edx
730 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
731
732 e8/call leaky-get-or-insert-slice/disp32
733
734 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
735
736 8b/copy 0/mod/indirect 0/rm32/eax . . . 3/r32/ebx . .
737
738 81 7/subop/compare 3/mod/direct 3/rm32/ebx . . . . . 0/imm32
739 0f 85/jump-if-not-equal $read-segments:loop/disp32
740
741
742 50/push-eax
743
744
745 68/push 1/imm32
746 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Segment-size/disp32
747 68/push Heap/imm32
748
749 e8/call new-stream/disp32
750
751 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
752
753 89/copy 3/mod/direct 3/rm32/ebx . . . 0/r32/eax . .
754
755 58/pop-to-eax
756
757 89/copy 0/mod/indirect 0/rm32/eax . . . 3/r32/ebx . .
758
759 $read-segments:regular-line:
760 +-- 9 lines: #? # print("regular line\n") ---------------------------------------------------------------------------------------------------------------
769 +-- 33 lines: #? # dump line -----------------------------------------------------------------------------------------------------------------------------
802
803
804 51/push-ecx
805
806 e8/call rewind-stream/disp32
807
808 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
809 +-- 9 lines: #? # print("write stream\n") ---------------------------------------------------------------------------------------------------------------
818
819
820 51/push-ecx
821 53/push-ebx
822
823 e8/call write-stream/disp32
824
825 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
826
827 +-- 9 lines: #? # print("loop\n") -----------------------------------------------------------------------------------------------------------------------
836 e9/jump $read-segments:loop/disp32
837 $read-segments:break:
838 $read-segments:end:
839
840 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x214/imm32
841
842 5e/pop-to-esi
843 5b/pop-to-ebx
844 5a/pop-to-edx
845 59/pop-to-ecx
846 58/pop-to-eax
847
848 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
849 5d/pop-to-ebp
850 c3/return
851
852 write-segments:
853
854
855
856
857
858
859
860
861
862
863 55/push-ebp
864 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
865
866 50/push-eax
867 52/push-edx
868 56/push-esi
869
870 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0xc/disp8 .
871
872 8b/copy 0/mod/indirect 6/rm32/esi . . . 2/r32/edx . .
873
874 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 0xc/imm32
875
876 01/add 3/mod/direct 2/rm32/edx . . . 6/r32/esi . .
877 $write-segments:loop:
878
879 39/compare 3/mod/direct 6/rm32/esi . . . 2/r32/edx . .
880 73/jump-if-greater-or-equal-unsigned $write-segments:break/disp8
881
882 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 .
883
884
885 50/push-eax
886 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
887
888 e8/call write-stream-data/disp32
889
890 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
891 $write-segments:continue:
892
893 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 8/imm32
894 eb/jump $write-segments:loop/disp8
895 $write-segments:break:
896
897
898 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
899
900 e8/call flush/disp32
901
902 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
903 $write-segments:end:
904
905 5e/pop-to-esi
906 5a/pop-to-edx
907 58/pop-to-eax
908
909 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
910 5d/pop-to-ebp
911 c3/return
912
913