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 e8/call syscall_exit/disp32
83
84
85
86
87
88 subx-assort:
89
90
91
92
93
94
95 55/push-ebp
96 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
97
98 51/push-ecx
99
100 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0xa0/imm32
101 68/push 0xa0/imm32/length
102 68/push 0/imm32/read
103 68/push 0/imm32/write
104 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
105
106
107 51/push-ecx
108
109 e8/call clear-stream/disp32
110
111 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
112 $subx-assort:read:
113 +-- 9 lines: #? # print("read\n") -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
122
123
124 51/push-ecx
125 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
126
127 e8/call read-segments/disp32
128
129 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
130 $subx-assort:write:
131 +-- 9 lines: #? # print("write\n") ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
140
141
142 51/push-ecx
143 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
144
145 e8/call write-segments/disp32
146
147 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
148 $subx-assort:end:
149
150 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xac/imm32
151
152 59/pop-to-ecx
153
154 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
155 5d/pop-to-ebp
156 c3/return
157
158 test-subx-assort:
159
160 55/push-ebp
161 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
162
163
164
165 68/push _test-input-stream/imm32
166
167 e8/call clear-stream/disp32
168
169 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
170
171
172 68/push $_test-input-buffered-file->buffer/imm32
173
174 e8/call clear-stream/disp32
175
176 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
177
178
179 68/push _test-output-stream/imm32
180
181 e8/call clear-stream/disp32
182
183 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
184
185
186 68/push $_test-output-buffered-file->buffer/imm32
187
188 e8/call clear-stream/disp32
189
190 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208 68/push "# comment 1\n"/imm32
209 68/push _test-input-stream/imm32
210
211 e8/call write/disp32
212
213 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
214
215
216 68/push " # comment 2 indented\n"/imm32
217 68/push _test-input-stream/imm32
218
219 e8/call write/disp32
220
221 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
222
223
224 68/push "== code 0x09000000\n"/imm32
225 68/push _test-input-stream/imm32
226
227 e8/call write/disp32
228
229 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
230
231
232 68/push "# comment 3 inside a segment\n"/imm32
233 68/push _test-input-stream/imm32
234
235 e8/call write/disp32
236
237 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
238
239
240 68/push "1\n"/imm32
241 68/push _test-input-stream/imm32
242
243 e8/call write/disp32
244
245 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
246
247
248 68/push Newline/imm32
249 68/push _test-input-stream/imm32
250
251 e8/call write/disp32
252
253 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
254
255
256 68/push "2 3 # comment 4 inline with other contents\n"/imm32
257 68/push _test-input-stream/imm32
258
259 e8/call write/disp32
260
261 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
262
263
264 68/push "== data 0x0a000000\n"/imm32
265 68/push _test-input-stream/imm32
266
267 e8/call write/disp32
268
269 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
270
271
272 68/push "4 5/imm32\n"/imm32
273 68/push _test-input-stream/imm32
274
275 e8/call write/disp32
276
277 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
278
279
280 68/push "== code\n"/imm32
281 68/push _test-input-stream/imm32
282
283 e8/call write/disp32
284
285 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
286
287
288 68/push "6 7\n"/imm32
289 68/push _test-input-stream/imm32
290
291 e8/call write/disp32
292
293 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
294
295
296 68/push "8 9\n"/imm32
297 68/push _test-input-stream/imm32
298
299 e8/call write/disp32
300
301 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
302
303
304 68/push "== code\n"/imm32
305 68/push _test-input-stream/imm32
306
307 e8/call write/disp32
308
309 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
310
311
312 68/push "10 11\n"/imm32
313 68/push _test-input-stream/imm32
314
315 e8/call write/disp32
316
317 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
318
319
320 68/push _test-output-buffered-file/imm32
321 68/push _test-input-buffered-file/imm32
322
323 e8/call subx-assort/disp32
324
325 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
326
327
328 68/push _test-output-buffered-file/imm32
329
330 e8/call flush/disp32
331
332 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
333
334
335
336
337
338
339
340
341
342 +-- 33 lines: #? # dump output ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
375
376
377 68/push "F - test-subx-assort/0"/imm32
378 68/push "== code 0x09000000"/imm32
379 68/push _test-output-stream/imm32
380
381 e8/call check-next-stream-line-equal/disp32
382
383 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
384
385
386 68/push "F - test-subx-assort/1"/imm32
387 68/push "1"/imm32
388 68/push _test-output-stream/imm32
389
390 e8/call check-next-stream-line-equal/disp32
391
392 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
393
394
395 68/push "F - test-subx-assort/2"/imm32
396 68/push "2 3 # comment 4 inline with other contents"/imm32
397 68/push _test-output-stream/imm32
398
399 e8/call check-next-stream-line-equal/disp32
400
401 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
402
403
404 68/push "F - test-subx-assort/3"/imm32
405 68/push "6 7"/imm32
406 68/push _test-output-stream/imm32
407
408 e8/call check-next-stream-line-equal/disp32
409
410 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
411
412
413 68/push "F - test-subx-assort/4"/imm32
414 68/push "8 9"/imm32
415 68/push _test-output-stream/imm32
416
417 e8/call check-next-stream-line-equal/disp32
418
419 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
420
421
422 68/push "F - test-subx-assort/5"/imm32
423 68/push "10 11"/imm32
424 68/push _test-output-stream/imm32
425
426 e8/call check-next-stream-line-equal/disp32
427
428 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
429
430
431 68/push "F - test-subx-assort/6"/imm32
432 68/push "== data 0x0a000000"/imm32
433 68/push _test-output-stream/imm32
434
435 e8/call check-next-stream-line-equal/disp32
436
437 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
438
439
440 68/push "F - test-subx-assort/7"/imm32
441 68/push "4 5/imm32"/imm32
442 68/push _test-output-stream/imm32
443
444 e8/call check-next-stream-line-equal/disp32
445
446 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
447
448 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
449 5d/pop-to-ebp
450 c3/return
451
452 read-segments:
453
454
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 55/push-ebp
488 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
489
490 50/push-eax
491 51/push-ecx
492 52/push-edx
493 53/push-ebx
494 56/push-esi
495 57/push-edi
496
497 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0x200/imm32
498 68/push 0x200/imm32/length
499 68/push 0/imm32/read
500 68/push 0/imm32/write
501 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
502
503 68/push 0/imm32/end
504 68/push 0/imm32/start
505 89/copy 3/mod/direct 2/rm32/edx . . . 4/r32/esp . .
506 $read-segments:loop:
507
508
509 51/push-ecx
510
511 e8/call clear-stream/disp32
512
513 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
514
515
516 51/push-ecx
517 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
518
519 e8/call read-line-buffered/disp32
520
521 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
522 $read-segments:check0:
523
524 81 7/subop/compare 0/mod/indirect 1/rm32/ecx . . . . . 0/imm32
525 0f 84/jump-if-= $read-segments:break/disp32
526 +-- 33 lines: #? # dump line -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
559
560
561 52/push-edx
562 51/push-ecx
563
564 e8/call next-word-or-string/disp32
565
566 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
567 $read-segments:check1:
568 +-- 9 lines: #? # print("check1\n") ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
577
578
579
580 52/push-edx
581
582 e8/call slice-empty?/disp32
583
584 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
585
586 3d/compare-eax-and 0/imm32/false
587 0f 85/jump-if-!= $read-segments:loop/disp32
588 $read-segments:check-for-comment:
589 +-- 9 lines: #? # print("check for comment\n") ----------------------------------------------------------------------------------------------------------------------------------------------------------------
598
599
600 8b/copy 0/mod/indirect 2/rm32/edx . . . 6/r32/esi . .
601
602 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . .
603 8a/copy-byte 0/mod/indirect 6/rm32/esi . . . 0/r32/AL . .
604
605 3d/compare-eax-and 0x23/imm32/hash
606 0f 84/jump-if-= $read-segments:loop/disp32
607 $read-segments:check-for-segment-header:
608 +-- 9 lines: #? # print("check for segment header\n") ---------------------------------------------------------------------------------------------------------------------------------------------------------
617 +-- 40 lines: #? # dump word-slice -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
657
658
659
660 68/push "=="/imm32
661 52/push-edx
662
663 e8/call slice-equal?/disp32
664
665 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
666
667 3d/compare-eax-and 0/imm32/false
668 0f 84/jump-if-= $read-segments:regular-line/disp32
669
670
671 52/push-edx
672 51/push-ecx
673
674 e8/call next-word-or-string/disp32
675
676 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
677 +-- 40 lines: #? # dump segment name ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
717
718
719
720 68/push Heap/imm32
721 68/push 0x10/imm32/row-size
722 52/push-edx
723 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
724
725 e8/call get-or-insert-slice/disp32
726
727 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
728
729 89/copy 3/mod/direct 7/rm32/edi . . . 0/r32/eax . .
730 +-- 33 lines: #? # print("slot: " segment-slot "\n") -----------------------------------------------------------------------------------------------------------------------------------------------------------
763
764 81 7/subop/compare 0/mod/indirect 7/rm32/edi . . . . . 0/imm32
765 0f 84/jump-if-= $read-segments:create-segment/disp32
766
767
768
769 ff 6/subop/push 1/mod/*+disp8 7/rm32/edi . . . . 4/disp8 .
770 ff 6/subop/push 0/mod/indirect 7/rm32/edi . . . . . .
771
772 e8/call lookup/disp32
773
774 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
775
776 89/copy 3/mod/direct 3/rm32/ebx . . . 0/r32/eax . .
777
778 e9/jump $read-segments:loop/disp32
779 $read-segments:create-segment:
780
781
782 57/push-edi
783 68/push 1/imm32
784 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Segment-size/disp32
785 68/push Heap/imm32
786
787 e8/call new-stream/disp32
788
789 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
790
791
792
793 ff 6/subop/push 1/mod/*+disp8 7/rm32/edi . . . . 4/disp8 .
794 ff 6/subop/push 0/mod/indirect 7/rm32/edi . . . . . .
795
796 e8/call lookup/disp32
797
798 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
799
800 89/copy 3/mod/direct 3/rm32/ebx . . . 0/r32/eax . .
801
802 $read-segments:regular-line:
803 +-- 9 lines: #? # print("regular line\n") ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
812 +-- 33 lines: #? # dump line -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
845 +-- 33 lines: #? # print("addr: " curr-segment->write "\n") ----------------------------------------------------------------------------------------------------------------------------------------------------
878 +-- 33 lines: #? # print("write: " curr-segment->write "\n") ---------------------------------------------------------------------------------------------------------------------------------------------------
911 +-- 33 lines: #? # print("size: " curr-segment->size "\n") -----------------------------------------------------------------------------------------------------------------------------------------------------
944
945
946 51/push-ecx
947
948 e8/call rewind-stream/disp32
949
950 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
951 +-- 9 lines: #? # print("write stream\n") ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
960
961
962 51/push-ecx
963 53/push-ebx
964
965 e8/call write-stream/disp32
966
967 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
968
969 +-- 9 lines: #? # print("loop\n") -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
978 e9/jump $read-segments:loop/disp32
979 $read-segments:break:
980 $read-segments:end:
981
982 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x214/imm32
983
984 5f/pop-to-edi
985 5e/pop-to-esi
986 5b/pop-to-ebx
987 5a/pop-to-edx
988 59/pop-to-ecx
989 58/pop-to-eax
990
991 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
992 5d/pop-to-ebp
993 c3/return
994
995 write-segments:
996
997
998
999
1000
1001
1002
1003
1004
1005
1006 55/push-ebp
1007 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
1008
1009 50/push-eax
1010 52/push-edx
1011 56/push-esi
1012
1013 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0xc/disp8 .
1014
1015 8b/copy 0/mod/indirect 6/rm32/esi . . . 2/r32/edx . .
1016
1017 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 0xc/imm32
1018
1019 01/add 3/mod/direct 2/rm32/edx . . . 6/r32/esi . .
1020 $write-segments:loop:
1021
1022 39/compare 3/mod/direct 6/rm32/esi . . . 2/r32/edx . .
1023 73/jump-if-addr>= $write-segments:break/disp8
1024
1025
1026 ff 6/subop/push 1/mod/*+disp8 6/rm32/esi . . . . 0xc/disp8 .
1027 ff 6/subop/push 1/mod/*+disp8 6/rm32/esi . . . . 8/disp8 .
1028
1029 e8/call lookup/disp32
1030
1031 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
1032
1033
1034 50/push-eax
1035 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
1036
1037 e8/call write-stream-data/disp32
1038
1039 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
1040 $write-segments:continue:
1041
1042 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 0x10/imm32
1043 eb/jump $write-segments:loop/disp8
1044 $write-segments:break:
1045
1046
1047 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
1048
1049 e8/call flush/disp32
1050
1051 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
1052 $write-segments:end:
1053
1054 5e/pop-to-esi
1055 5a/pop-to-edx
1056 58/pop-to-eax
1057
1058 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
1059 5d/pop-to-ebp
1060 c3/return
1061
1062