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 $subx-assort-main:interactive/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 $subx-assort-main:interactive/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 $subx-assort-main:end/disp8
61 $subx-assort-main:interactive:
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 subx-assort/disp32
77
78 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
79
80 bb/copy-to-ebx 0/imm32
81 $subx-assort-main:end:
82 b8/copy-to-eax 1/imm32/exit
83 cd/syscall 0x80/imm8
84
85
86
87
88
89 subx-assort:
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 $subx-assort: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 $subx-assort: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 $subx-assort: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-subx-assort:
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 68/push _test-input-buffered-file->buffer/imm32
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 68/push _test-output-buffered-file->buffer/imm32
188
189 e8/call clear-stream/disp32
190
191 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209 68/push "# comment 1\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 2 indented\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 "== code 0x09000000\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 "# comment 3 inside a segment\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 "1\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 Newline/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 "2 3 # comment 4 inline with other contents\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 "== data 0x0a000000\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 "4 5/imm32\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 "== code\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 "6 7\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 "8 9\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 "== code\n"/imm32
306 68/push _test-input-stream/imm32
307
308 e8/call write/disp32
309
310 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
311
312
313 68/push "10 11\n"/imm32
314 68/push _test-input-stream/imm32
315
316 e8/call write/disp32
317
318 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
319
320
321 68/push _test-output-buffered-file/imm32
322 68/push _test-input-buffered-file/imm32
323
324 e8/call subx-assort/disp32
325
326 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
327
328
329 68/push _test-output-buffered-file/imm32
330
331 e8/call flush/disp32
332
333 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
334
335
336
337
338
339
340
341
342
343 +-- 33 lines: #? # dump output ---------------------------------------------------------------------------------------------------------------------------
376
377
378 68/push "F - test-subx-assort/0"/imm32
379 68/push "== code 0x09000000"/imm32
380 68/push _test-output-stream/imm32
381
382 e8/call check-next-stream-line-equal/disp32
383
384 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
385
386
387 68/push "F - test-subx-assort/1"/imm32
388 68/push "1"/imm32
389 68/push _test-output-stream/imm32
390
391 e8/call check-next-stream-line-equal/disp32
392
393 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
394
395
396 68/push "F - test-subx-assort/2"/imm32
397 68/push "2 3 # comment 4 inline with other contents"/imm32
398 68/push _test-output-stream/imm32
399
400 e8/call check-next-stream-line-equal/disp32
401
402 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
403
404
405 68/push "F - test-subx-assort/3"/imm32
406 68/push "6 7"/imm32
407 68/push _test-output-stream/imm32
408
409 e8/call check-next-stream-line-equal/disp32
410
411 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
412
413
414 68/push "F - test-subx-assort/4"/imm32
415 68/push "8 9"/imm32
416 68/push _test-output-stream/imm32
417
418 e8/call check-next-stream-line-equal/disp32
419
420 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
421
422
423 68/push "F - test-subx-assort/5"/imm32
424 68/push "10 11"/imm32
425 68/push _test-output-stream/imm32
426
427 e8/call check-next-stream-line-equal/disp32
428
429 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
430
431
432 68/push "F - test-subx-assort/6"/imm32
433 68/push "== data 0x0a000000"/imm32
434 68/push _test-output-stream/imm32
435
436 e8/call check-next-stream-line-equal/disp32
437
438 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
439
440
441 68/push "F - test-subx-assort/7"/imm32
442 68/push "4 5/imm32"/imm32
443 68/push _test-output-stream/imm32
444
445 e8/call check-next-stream-line-equal/disp32
446
447 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
448
449 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
450 5d/pop-to-ebp
451 c3/return
452
453
454 read-segments:
455
456
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 55/push-ebp
490 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
491
492 50/push-eax
493 51/push-ecx
494 52/push-edx
495 53/push-ebx
496 56/push-esi
497
498 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0x200/imm32
499 68/push 0x200/imm32/length
500 68/push 0/imm32/read
501 68/push 0/imm32/write
502 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
503
504 68/push 0/imm32/end
505 68/push 0/imm32/start
506 89/copy 3/mod/direct 2/rm32/edx . . . 4/r32/esp . .
507 $read-segments:loop:
508
509
510 51/push-ecx
511
512 e8/call clear-stream/disp32
513
514 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
515
516
517 51/push-ecx
518 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
519
520 e8/call read-line-buffered/disp32
521
522 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
523 $read-segments:check0:
524
525 81 7/subop/compare 0/mod/indirect 1/rm32/ecx . . . . . 0/imm32
526 0f 84/jump-if-equal $read-segments:break/disp32
527 +-- 33 lines: #? # dump line -----------------------------------------------------------------------------------------------------------------------------
560
561
562 52/push-edx
563 51/push-ecx
564
565 e8/call next-word-or-string/disp32
566
567 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
568 $read-segments:check1:
569 +-- 9 lines: #? # print("check1\n") ---------------------------------------------------------------------------------------------------------------------
578
579
580
581 52/push-edx
582
583 e8/call slice-empty?/disp32
584
585 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
586
587 3d/compare-eax-and 0/imm32
588 0f 85/jump-if-not-equal $read-segments:loop/disp32
589 $read-segments:check-for-comment:
590 +-- 9 lines: #? # print("check for comment\n") ----------------------------------------------------------------------------------------------------------
599
600
601 8b/copy 0/mod/indirect 2/rm32/edx . . . 6/r32/esi . .
602
603 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . .
604 8a/copy-byte 0/mod/indirect 6/rm32/esi . . . 0/r32/AL . .
605
606 3d/compare-eax-and 0x23/imm32/hash
607 0f 84/jump-if-equal $read-segments:loop/disp32
608 $read-segments:check-for-segment-header:
609 +-- 9 lines: #? # print("check for segment header\n") ---------------------------------------------------------------------------------------------------
618 +-- 40 lines: #? # dump word-slice -----------------------------------------------------------------------------------------------------------------------
658
659
660
661 68/push "=="/imm32
662 52/push-edx
663
664 e8/call slice-equal?/disp32
665
666 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
667
668 3d/compare-eax-and 0/imm32
669 0f 84/jump-if-equal $read-segments:regular-line/disp32
670
671
672 52/push-edx
673 51/push-ecx
674
675 e8/call next-word-or-string/disp32
676
677 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
678 +-- 40 lines: #? # dump segment name ---------------------------------------------------------------------------------------------------------------------
718
719
720 68/push 8/imm32/row-size
721 52/push-edx
722 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
723
724 e8/call leaky-get-or-insert-slice/disp32
725
726 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
727
728 8b/copy 0/mod/indirect 0/rm32/eax . . . 3/r32/ebx . .
729
730 81 7/subop/compare 3/mod/direct 3/rm32/ebx . . . . . 0/imm32
731 0f 85/jump-if-not-equal $read-segments:loop/disp32
732
733
734 50/push-eax
735
736
737 68/push 1/imm32
738 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Segment-size/disp32
739 68/push Heap/imm32
740
741 e8/call new-stream/disp32
742
743 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
744
745 89/copy 3/mod/direct 3/rm32/ebx . . . 0/r32/eax . .
746
747 58/pop-to-eax
748
749 89/copy 0/mod/indirect 0/rm32/eax . . . 3/r32/ebx . .
750
751 $read-segments:regular-line:
752 +-- 9 lines: #? # print("regular line\n") ---------------------------------------------------------------------------------------------------------------
761 +-- 33 lines: #? # dump line -----------------------------------------------------------------------------------------------------------------------------
794
795
796 51/push-ecx
797
798 e8/call rewind-stream/disp32
799
800 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
801 +-- 9 lines: #? # print("write stream\n") ---------------------------------------------------------------------------------------------------------------
810
811
812 51/push-ecx
813 53/push-ebx
814
815 e8/call write-stream/disp32
816
817 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
818
819 +-- 9 lines: #? # print("loop\n") -----------------------------------------------------------------------------------------------------------------------
828 e9/jump $read-segments:loop/disp32
829 $read-segments:break:
830 $read-segments:end:
831
832 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x214/imm32
833
834 5e/pop-to-esi
835 5b/pop-to-ebx
836 5a/pop-to-edx
837 59/pop-to-ecx
838 58/pop-to-eax
839
840 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
841 5d/pop-to-ebp
842 c3/return
843
844 write-segments:
845
846
847
848
849
850
851
852
853
854
855 55/push-ebp
856 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
857
858 50/push-eax
859 52/push-edx
860 56/push-esi
861
862 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0xc/disp8 .
863
864 8b/copy 0/mod/indirect 6/rm32/esi . . . 2/r32/edx . .
865
866 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 0xc/imm32
867
868 01/add 3/mod/direct 2/rm32/edx . . . 6/r32/esi . .
869 $write-segments:loop:
870
871 39/compare 3/mod/direct 6/rm32/esi . . . 2/r32/edx . .
872 73/jump-if-greater-or-equal-unsigned $write-segments:break/disp8
873
874 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 .
875
876
877 50/push-eax
878 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
879
880 e8/call write-stream-data/disp32
881
882 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
883 $write-segments:continue:
884
885 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 8/imm32
886 eb/jump $write-segments:loop/disp8
887 $write-segments:break:
888
889
890 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
891
892 e8/call flush/disp32
893
894 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
895 $write-segments:end:
896
897 5e/pop-to-esi
898 5a/pop-to-edx
899 58/pop-to-eax
900
901 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
902 5d/pop-to-ebp
903 c3/return
904
905