https://github.com/akkartik/mu/blob/master/subx/apps/hex.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14 == code
15
16
17
18
19
20
21
22
23
24
25
26 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
27
28
29 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0/disp8 1/imm32
30 7e/jump-if-lesser-or-equal $run-main/disp8
31
32
33 68/push "test"/imm32
34 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x8/disp8
35
36 e8/call kernel-string-equal/disp32
37
38 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
39
40 3d/compare-EAX 1/imm32
41 75/jump-if-not-equal $run-main/disp8
42
43
44
45
46 e8/call run-tests/disp32
47 8b/copy 0/mod/indirect 5/rm32/.disp32 3/r32/EBX Num-test-failures/disp32
48 eb/jump $main:end/disp8
49 $run-main:
50
51
52 81 5/subop/subtract 3/mod/direct 4/rm32/ESP 8/imm32
53 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none 0/r32/EAX
54
55
56 c7/copy 0/mod/direct 0/rm32/EAX 0/imm32
57
58
59 50/push-EAX/ed
60 68/push 2/imm32/stderr
61 68/push 1/imm32/stdout
62 68/push Stdin/imm32
63
64 e8/call convert/disp32
65
66 81 0/subop/add 3/mod/direct 4/rm32/ESP 0x10/imm32
67
68 bb/copy-to-EBX 0/imm32
69 $main:end:
70 b8/copy-to-EAX 1/imm32/exit
71 cd/syscall 0x80/imm8
72
73
74 convert:
75
76
77
78
79
80
81
82
83 55/push-EBP
84 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
85
86
87
88 81 5/subop/subtract 3/mod/direct 4/rm32/ESP 0x400/imm32
89 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none 1/r32/ECX
90
91
92 c7/copy 1/mod/*+disp8 1/rm32/ECX 8/disp8 0x3f4/imm32
93
94
95 51/push-ECX
96
97 e8/call clear-stream/disp32
98
99 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
100 $convert:loop:
101
102
103 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
104 5d/pop-to-EBP
105 c3/return
106
107
108
109
110
111
112
113 convert-next-hex-byte:
114
115
116
117
118
119
120
121
122
123
124 55/push-EBP
125 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
126
127
128
129 81 5/subop/subtract 3/mod/direct 4/rm32/ESP 0x400/imm32
130 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none 1/r32/ECX
131
132
133 c7/copy 1/mod/*+disp8 1/rm32/ECX 8/disp8 0x3f4/imm32
134
135
136 51/push-ECX
137
138 e8/call clear-stream/disp32
139
140 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
141 $convert:loop:
142
143
144 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
145 5d/pop-to-EBP
146 c3/return
147
148
149
150
151
152 scan-next-byte:
153
154
155
156
157
158
159
160
161
162
163 55/push-EBP
164 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
165
166 $scan-next-byte:loop:
167
168
169 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x8/disp8
170
171 e8/call read-byte/disp32
172
173 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
174
175
176 50/push-EAX
177
178
179 50/push-EAX
180
181 e8/call is-hex-lowercase-byte?/disp32
182
183 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
184
185 81 7/subop/compare 3/mod/direct 0/rm32/EAX 0/imm32
186
187 58/pop-to-EAX
188
189 75/jump-if-not-equal $scan-next-byte:end/disp8
190 $scan-next-byte:check1:
191
192 81 7/subop/compare 3/mod/direct 0/rm32/EAX 0x20/imm32
193 74/jump-if-equal $scan-next-byte:loop/disp8
194
195 81 7/subop/compare 3/mod/direct 0/rm32/EAX 0x9/imm32
196 74/jump-if-equal $scan-next-byte:loop/disp8
197
198 81 7/subop/compare 3/mod/direct 0/rm32/EAX 0xa/imm32
199 74/jump-if-equal $scan-next-byte:loop/disp8
200 $scan-next-byte:check2:
201
202 3d/compare-with-EAX 0x23/imm32
203 75/jump-if-not-equal $scan-next-byte:check3/disp8
204
205
206 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x8/disp8
207
208 e8/call skip-until-newline/disp32
209
210 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
211 eb/jump $scan-next-byte:loop/disp8
212 $scan-next-byte:check3:
213
214
215
216 50/push-EAX
217 68/push "scan-next-byte: invalid byte"/imm32
218 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
219 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x10/disp8
220
221 e8/call error-byte/disp32
222 $scan-next-byte:end:
223
224
225 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
226 5d/pop-to-EBP
227 c3/return
228
229 test-scan-next-byte:
230
231
232
233
234 68/push _test-stream/imm32
235
236 e8/call clear-stream/disp32
237
238 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
239
240
241 b8/copy-to-EAX _test-buffered-file/imm32
242 05/add-to-EAX 4/imm32
243 50/push-EAX
244
245 e8/call clear-stream/disp32
246
247 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
248
249
250
251 68/push "abc"/imm32
252 68/push _test-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 _test-buffered-file/imm32
260
261 e8/call scan-next-byte/disp32
262
263 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
264
265
266 68/push "F - test-scan-next-byte"/imm32
267 68/push 0x61/imm32/a
268 50/push-EAX
269
270 e8/call check-ints-equal/disp32
271
272 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
273
274 c3/return
275
276 test-scan-next-byte-skips-whitespace:
277
278
279
280
281 68/push _test-stream/imm32
282
283 e8/call clear-stream/disp32
284
285 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
286
287
288 b8/copy-to-EAX _test-buffered-file/imm32
289 05/add-to-EAX 4/imm32
290 50/push-EAX
291
292 e8/call clear-stream/disp32
293
294 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
295
296
297
298 68/push " abc"/imm32
299 68/push _test-stream/imm32
300
301 e8/call write/disp32
302
303 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
304
305
306 68/push _test-buffered-file/imm32
307
308 e8/call scan-next-byte/disp32
309
310 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
311
312
313 68/push "F - test-scan-next-byte-skips-whitespace"/imm32
314 68/push 0x61/imm32/a
315 50/push-EAX
316
317 e8/call check-ints-equal/disp32
318
319 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
320
321 c3/return
322
323 test-scan-next-byte-skips-comment:
324
325
326
327
328 68/push _test-stream/imm32
329
330 e8/call clear-stream/disp32
331
332 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
333
334
335 b8/copy-to-EAX _test-buffered-file/imm32
336 05/add-to-EAX 4/imm32
337 50/push-EAX
338
339 e8/call clear-stream/disp32
340
341 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
342
343
344
345 68/push "#x"/imm32
346 68/push _test-stream/imm32
347
348 e8/call write/disp32
349
350 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
351
352
353 68/push Newline/imm32
354 68/push _test-stream/imm32
355
356 e8/call write/disp32
357
358 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
359
360
361 68/push "ab"/imm32
362 68/push _test-stream/imm32
363
364 e8/call write/disp32
365
366 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
367
368
369 68/push _test-buffered-file/imm32
370
371 e8/call scan-next-byte/disp32
372
373 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
374
375
376 68/push "F - test-scan-next-byte-skips-comment"/imm32
377 68/push 0x61/imm32/a
378 50/push-EAX
379
380 e8/call check-ints-equal/disp32
381
382 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
383
384 c3/return
385
386 test-scan-next-byte-skips-comment-and-whitespace:
387
388
389
390
391 68/push _test-stream/imm32
392
393 e8/call clear-stream/disp32
394
395 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
396
397
398 b8/copy-to-EAX _test-buffered-file/imm32
399 05/add-to-EAX 4/imm32
400 50/push-EAX
401
402 e8/call clear-stream/disp32
403
404 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
405
406
407
408 68/push "#x"/imm32
409 68/push _test-stream/imm32
410
411 e8/call write/disp32
412
413 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
414
415
416 68/push Newline/imm32
417 68/push _test-stream/imm32
418
419 e8/call write/disp32
420
421 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
422
423
424 68/push " ab"/imm32
425 68/push _test-stream/imm32
426
427 e8/call write/disp32
428
429 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
430
431
432 68/push _test-buffered-file/imm32
433
434 e8/call scan-next-byte/disp32
435
436 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
437
438
439 68/push "F - test-scan-next-byte-skips-comment"/imm32
440 68/push 0x61/imm32/a
441 50/push-EAX
442
443 e8/call check-ints-equal/disp32
444
445 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
446
447 c3/return
448
449 test-scan-next-byte-skips-whitespace-and-comment:
450
451
452
453
454 68/push _test-stream/imm32
455
456 e8/call clear-stream/disp32
457
458 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
459
460
461 b8/copy-to-EAX _test-buffered-file/imm32
462 05/add-to-EAX 4/imm32
463 50/push-EAX
464
465 e8/call clear-stream/disp32
466
467 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
468
469
470
471 68/push " #x"/imm32
472 68/push _test-stream/imm32
473
474 e8/call write/disp32
475
476 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
477
478
479 68/push Newline/imm32
480 68/push _test-stream/imm32
481
482 e8/call write/disp32
483
484 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
485
486
487 68/push "ab"/imm32
488 68/push _test-stream/imm32
489
490 e8/call write/disp32
491
492 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
493
494
495 68/push _test-buffered-file/imm32
496
497 e8/call scan-next-byte/disp32
498
499 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
500
501
502 68/push "F - test-scan-next-byte-skips-comment"/imm32
503 68/push 0x61/imm32/a
504 50/push-EAX
505
506 e8/call check-ints-equal/disp32
507
508 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
509
510 c3/return
511
512 test-scan-next-byte-reads-final-byte:
513
514
515
516
517 68/push _test-stream/imm32
518
519 e8/call clear-stream/disp32
520
521 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
522
523
524 b8/copy-to-EAX _test-buffered-file/imm32
525 05/add-to-EAX 4/imm32
526 50/push-EAX
527
528 e8/call clear-stream/disp32
529
530 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
531
532
533
534 68/push "a"/imm32
535 68/push _test-stream/imm32
536
537 e8/call write/disp32
538
539 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
540
541
542 68/push _test-buffered-file/imm32
543
544 e8/call scan-next-byte/disp32
545
546 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
547
548
549 68/push "F - test-scan-next-byte-skips-comment"/imm32
550 68/push 0x61/imm32/a
551 50/push-EAX
552
553 e8/call check-ints-equal/disp32
554
555 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
556
557 c3/return
558
559 is-hex-lowercase-byte?:
560
561 55/push-EBP
562 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
563
564 51/push-ECX
565
566 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 1/r32/ECX 0x8/disp8
567
568 b8/copy-to-EAX 0/imm32/false
569 81 7/subop/compare 3/mod/direct 1/rm32/ECX 0x30/imm32
570 7c/jump-if-lesser $is-hex-lowercase-byte?:end/disp8
571
572 81 7/subop/compare 3/mod/direct 1/rm32/ECX 0x66/imm32
573 7f/jump-if-greater $is-hex-lowercase-byte?:end/disp8
574
575 b8/copy-to-EAX 1/imm32/true
576 81 7/subop/compare 3/mod/direct 1/rm32/ECX 0x39/imm32
577 7e/jump-if-lesser-or-equal $is-hex-lowercase-byte?:end/disp8
578
579 81 7/subop/compare 3/mod/direct 1/rm32/ECX 0x61/imm32
580 7d/jump-if-greater-or-equal $is-hex-lowercase-byte?:end/disp8
581
582 b8/copy-to-EAX 0/imm32/false
583 $is-hex-lowercase-byte?:end:
584
585 59/pop-to-ECX
586
587 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
588 5d/pop-to-EBP
589 c3/return
590
591 test-hex-below-0:
592
593
594 68/push 0x2f/imm32
595
596 e8/call is-hex-lowercase-byte?/disp32
597
598 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
599
600
601 68/push "F - test-hex-below-0"/imm32
602 68/push 0/imm32/false
603 50/push-EAX
604
605 e8/call check-ints-equal/disp32
606
607 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
608 c3/return
609
610 test-hex-0-to-9:
611
612
613 68/push 0x30/imm32
614
615 e8/call is-hex-lowercase-byte?/disp32
616
617 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
618
619
620 68/push "F - test-hex-at-0"/imm32
621 68/push 1/imm32/true
622 50/push-EAX
623
624 e8/call check-ints-equal/disp32
625
626 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
627
628
629 68/push 0x39/imm32
630
631 e8/call is-hex-lowercase-byte?/disp32
632
633 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
634
635
636 68/push "F - test-hex-at-9"/imm32
637 68/push 1/imm32/true
638 50/push-EAX
639
640 e8/call check-ints-equal/disp32
641
642 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
643 c3/return
644
645 test-hex-above-9-to-a:
646
647
648 68/push 0x3a/imm32
649
650 e8/call is-hex-lowercase-byte?/disp32
651
652 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
653
654
655 68/push "F - test-hex-above-9-to-a"/imm32
656 68/push 0/imm32/false
657 50/push-EAX
658
659 e8/call check-ints-equal/disp32
660
661 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
662 c3/return
663
664 test-hex-a-to-f:
665
666
667 68/push 0x61/imm32
668
669 e8/call is-hex-lowercase-byte?/disp32
670
671 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
672
673
674 68/push "F - test-hex-at-a"/imm32
675 68/push 1/imm32/true
676 50/push-EAX
677
678 e8/call check-ints-equal/disp32
679
680 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
681
682
683 68/push 0x66/imm32
684
685 e8/call is-hex-lowercase-byte?/disp32
686
687 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
688
689
690 68/push "F - test-hex-at-f"/imm32
691 68/push 1/imm32/true
692 50/push-EAX
693
694 e8/call check-ints-equal/disp32
695
696 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
697 c3/return
698
699 test-hex-above-f:
700
701
702 68/push 0x67/imm32
703
704 e8/call is-hex-lowercase-byte?/disp32
705
706 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
707
708
709 68/push "F - test-hex-above-f"/imm32
710 68/push 0/imm32/false
711 50/push-EAX
712
713 e8/call check-ints-equal/disp32
714
715 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
716 c3/return
717
718 skip-until-newline:
719
720
721
722
723
724
725
726
727 55/push-EBP
728 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
729
730 50/push-EAX
731 $skip-until-newline:loop:
732
733
734 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x8/disp8
735
736 e8/call read-byte/disp32
737
738 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
739
740 81 7/subop/compare 3/mod/direct 0/rm32/EAX 0xffffffff/imm32
741 74/jump-if-equal $skip-until-newline:end/disp8
742 $aa:
743
744 81 7/subop/compare 3/mod/direct 0/rm32/EAX 0xa/imm32
745 75/jump-if-not-equal $skip-until-newline:loop/disp8
746 $skip-until-newline:end:
747
748 58/pop-to-EAX
749
750 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
751 5d/pop-to-EBP
752 c3/return
753
754 test-skip-until-newline:
755
756
757
758
759 68/push _test-stream/imm32
760
761 e8/call clear-stream/disp32
762
763 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
764
765
766 b8/copy-to-EAX _test-buffered-file/imm32
767 05/add-to-EAX 4/imm32
768 50/push-EAX
769
770 e8/call clear-stream/disp32
771
772 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
773
774
775
776 68/push "abc"/imm32
777 68/push _test-stream/imm32
778
779 e8/call write/disp32
780
781 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
782
783
784 68/push Newline/imm32
785 68/push _test-stream/imm32
786
787 e8/call write/disp32
788
789 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
790
791
792 68/push "de"/imm32
793 68/push _test-stream/imm32
794
795 e8/call write/disp32
796
797 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
798
799
800 68/push _test-buffered-file/imm32
801
802 e8/call skip-until-newline/disp32
803
804 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
805
806
807 68/push "F - test-skip-until-newline"/imm32
808 68/push 4/imm32
809 b8/copy-to-EAX _test-buffered-file/imm32
810 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX 8/disp8
811
812 e8/call check-ints-equal/disp32
813
814 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
815
816 c3/return
817
818 == data
819
820