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-<= $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/false
55 74/jump-if-= $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
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-= $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-or-string/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/false
590 0f 85/jump-if-!= $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-= $read-segments:loop/disp32
610 $read-segments:check-for-segment-header:
611 +-- 9 lines: #? # print("check for segment header\n") ------------------------------------------------------------------------------------------------------------------------------
620 +-- 40 lines: #? # dump word-slice --------------------------------------------------------------------------------------------------------------------------------------------------
660
661
662
663 68/push "=="/imm32
664 52/push-edx
665
666 e8/call slice-equal?/disp32
667
668 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
669
670 3d/compare-eax-and 0/imm32/false
671 0f 84/jump-if-= $read-segments:regular-line/disp32
672
673
674 52/push-edx
675 51/push-ecx
676
677 e8/call next-word-or-string/disp32
678
679 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
680 +-- 40 lines: #? # dump segment name ------------------------------------------------------------------------------------------------------------------------------------------------
720
721
722 68/push 8/imm32/row-size
723 52/push-edx
724 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
725
726 e8/call leaky-get-or-insert-slice/disp32
727
728 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
729
730 8b/copy 0/mod/indirect 0/rm32/eax . . . 3/r32/ebx . .
731
732 81 7/subop/compare 3/mod/direct 3/rm32/ebx . . . . . 0/imm32
733 0f 85/jump-if-!= $read-segments:loop/disp32
734
735
736 50/push-eax
737
738
739 68/push 1/imm32
740 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Segment-size/disp32
741 68/push Heap/imm32
742
743 e8/call new-stream/disp32
744
745 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
746
747 89/copy 3/mod/direct 3/rm32/ebx . . . 0/r32/eax . .
748
749 58/pop-to-eax
750
751 89/copy 0/mod/indirect 0/rm32/eax . . . 3/r32/ebx . .
752
753 $read-segments:regular-line:
754 +-- 9 lines: #? # print("regular line\n") ------------------------------------------------------------------------------------------------------------------------------------------
763 +-- 33 lines: #? # dump line --------------------------------------------------------------------------------------------------------------------------------------------------------
796
797
798 51/push-ecx
799
800 e8/call rewind-stream/disp32
801
802 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
803 +-- 9 lines: #? # print("write stream\n") ------------------------------------------------------------------------------------------------------------------------------------------
812
813
814 51/push-ecx
815 53/push-ebx
816
817 e8/call write-stream/disp32
818
819 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
820
821 +-- 9 lines: #? # print("loop\n") --------------------------------------------------------------------------------------------------------------------------------------------------
830 e9/jump $read-segments:loop/disp32
831 $read-segments:break:
832 $read-segments:end:
833
834 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x214/imm32
835
836 5e/pop-to-esi
837 5b/pop-to-ebx
838 5a/pop-to-edx
839 59/pop-to-ecx
840 58/pop-to-eax
841
842 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
843 5d/pop-to-ebp
844 c3/return
845
846 write-segments:
847
848
849
850
851
852
853
854
855
856
857 55/push-ebp
858 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
859
860 50/push-eax
861 52/push-edx
862 56/push-esi
863
864 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0xc/disp8 .
865
866 8b/copy 0/mod/indirect 6/rm32/esi . . . 2/r32/edx . .
867
868 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 0xc/imm32
869
870 01/add 3/mod/direct 2/rm32/edx . . . 6/r32/esi . .
871 $write-segments:loop:
872
873 39/compare 3/mod/direct 6/rm32/esi . . . 2/r32/edx . .
874 73/jump-if-addr>= $write-segments:break/disp8
875
876 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 .
877
878
879 50/push-eax
880 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
881
882 e8/call write-stream-data/disp32
883
884 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
885 $write-segments:continue:
886
887 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 8/imm32
888 eb/jump $write-segments:loop/disp8
889 $write-segments:break:
890
891
892 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
893
894 e8/call flush/disp32
895
896 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
897 $write-segments:end:
898
899 5e/pop-to-esi
900 5a/pop-to-edx
901 58/pop-to-eax
902
903 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
904 5d/pop-to-ebp
905 c3/return
906
907