https://github.com/akkartik/mu/blob/master/apps/crenshaw2-1b.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 == code
29
30
31
32
33 Entry:
34
35 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
36
37
38
39
40 68/push Heap/imm32
41 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Heap-size/disp32
42
43 e8/call new-segment/disp32
44
45 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
46
47
48
49 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 0/disp8 1/imm32
50 7e/jump-if-<= $run-main/disp8
51
52
53
54 68/push "test"/imm32
55 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
56
57 e8/call kernel-string-equal?/disp32
58
59 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
60
61 3d/compare-eax-and 0/imm32/false
62 74/jump-if-= $run-main/disp8
63
64 e8/call run-tests/disp32
65
66 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32
67 eb/jump $main:end/disp8
68 $run-main:
69
70
71 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 8/imm32
72 89/copy 3/mod/direct 0/rm32/eax . . . 4/r32/esp . .
73
74
75 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32
76
77
78 50/push-eax/ed
79 68/push 2/imm32/stderr
80 68/push 1/imm32/stdout
81 68/push Stdin/imm32
82
83 e8/call compile/disp32
84
85 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
86
87 bb/copy-to-ebx 0/imm32
88 $main:end:
89 b8/copy-to-eax 1/imm32/exit
90 cd/syscall 0x80/imm8
91
92
93 compile:
94
95 55/push-ebp
96 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
97
98 50/push-eax
99 51/push-ecx
100
101
102
103 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
104
105 e8/call get-char/disp32
106
107 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
108
109
110
111
112
113 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0x13/imm32
114 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
115
116
117 c7 0/subop/copy 1/mod/*+disp8 1/rm32/ecx . . . . 8/disp8 7/imm32
118
119
120 51/push-ecx
121
122 e8/call clear-stream/disp32
123
124 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . (lineNum);
/* Always jump to new location even if the line was hidden inside a fold, or
* we corrected the raw number to a line ID.
*/
if (lineElem) {
lineElem.scrollIntoView(true);
}
return true;
}
if ('onhashchange' in window) {
window.onhashchange = JumpToLine;
}
-->
</script>
</head>
<body onload='JumpToLine();'>
<a href='https://github.com/akkartik/mu/blob/master/apps/ex4.subx'>https://github.com/akkartik/mu/blob/master/apps/ex4.subx</a>
<pre id='vimCodeElement'>
<span id="L1" class="LineNr"> 1 </span><span class="subxComment"># Read a character from stdin, save it to a global, write it to stdout.</span>
<span id="L2" class="LineNr"> 2 </span><span class="subxComment">#</span>
<span id="L3" class="LineNr"> 3 </span><span class="subxComment"># To run:</span>
<span id="L4" class="LineNr"> 4 </span><span class="subxComment"># $ ./bootstrap translate init.linux apps/ex4.subx -o apps/ex4</span>
<span id="L5" class="LineNr"> 5 </span><span class="subxComment"># $ ./bootstrap run apps/ex4</span>
<span id="L6" class="LineNr"> 6 </span>
<span id="L7" class="LineNr"> 7 </span>== data
<span id="L8" class="LineNr"> 8 </span>
<span id="L9" class="LineNr"> 9 </span><span class="subxComment"># the global variable we save to</span>
<span id="L10" class="LineNr">10 </span><span class="SpecialChar">X</span>:
<span id="L11" class="LineNr">11 </span> 0/imm32 <span class="subxComment"># space for read() to write to</span>
<span id="L12" class="LineNr">12 </span>
<span id="L13" class="LineNr">13 </span>== code
<span id="L14" class="LineNr">14 </span>
<span id="L15" class="LineNr">15 </span><span class="SpecialChar">Entry</span>:
<span id="L16" class="LineNr">16 </span><span class="subxComment"># read(stdin, X, 1)</span>
<span id="L17" class="LineNr">17 </span><span class="subxS1Comment"># . fd = 0 (stdin)</span>
<span id="L18" class="LineNr">18 </span>bb/copy-to-ebx 0/imm32
<span id="L19" class="LineNr">19 </span><span class="subxS1Comment"># . data = X (location to write result to)</span>
<span id="L20" class="LineNr">20 </span>b9/copy-to-ecx <span class="SpecialChar"><a href='ex4.subx.html#L10'>X</a></span>/imm32
<span id="L21" class="LineNr">21 </span><span class="subxS1Comment"># . size = 1 character</span>
<span id="L22" class="LineNr">22 </span>ba/copy-to-edx 1/imm32
<span id="L23" class="LineNr">23 </span><span class="subxS1Comment"># . syscall</span>
<span id="L24" class="LineNr">24 </span>e8/call syscall_read/disp32
<span id="L25" class="LineNr">25 </span>
<span id="L26" class="LineNr">26 </span><span class="subxComment"># write(stdout, X, 1)</span>
<span id="L27" class="LineNr">27 </span><span class="subxS1Comment"># . fd = 1 (stdout)</span>
<span id="L28" class="LineNr">28 </span>bb/copy-to-ebx 1/imm32
<span id="L29" class="LineNr">29 </span><span class="subxS1Comment"># . initialize X (location to read from)</span>
<span id="L30" class="LineNr">30 </span>b9/copy-to-ecx <span class="SpecialChar"><a href='ex4.subx.html#L10'>X</a></span>/imm32
<span id="L31" class="LineNr">31 </span><span class="subxS1Comment"># . size = 1 character</span>
<span id="L32" class="LineNr">32 </span>ba/copy-to-edx 1/imm32
<span id="L33" class="LineNr">33 </span><span class="subxS1Comment"># . syscall</span>
<span id="L34" class="LineNr">34 </span>e8/call syscall_write/disp32
<span id="L35" class="LineNr">35 </span>
<span id="L36" class="LineNr">36 </span><span class="subxComment"># exit(ebx)</span>
<span id="L37" class="LineNr">37 </span>e8/call syscall_exit/disp32
<span id="L38" class="LineNr">38 </span>
<span id="L39" class="LineNr">39 </span><span class="subxS2Comment"># . . vim:nowrap:textwidth=0</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
">272 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
273 $get-num:loop-stage2:
274
275 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 1/index/ecx . 3/r32/ebx 0xc/disp8 .
276 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 0/r32/eax Look/disp32 .
277 88/copy-byte 0/mod/indirect 3/rm32/ebx . . . 0/r32/AL . .
278
279 41/increment-ecx
280
281
282 56/push-esi
283
284 e8/call get-char/disp32
285
286 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
287
288
289
290 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Look/disp32 .
291
292 e8/call is-digit?/disp32
293
294 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
295
296 3d/compare-eax-and 0/imm32/false
297 0f 85/jump-if-!= $get-num:loop/disp32
298 $get-num:loop-end:
299
300 89/copy 0/mod/indirect 7/rm32/edi . . . 1/r32/ecx . .
301 $get-num:end:
302
303 5f/pop-to-edi
304 5e/pop-to-esi
305 5b/pop-to-ebx
306 5a/pop-to-edx
307 59/pop-to-ecx
308 58/pop-to-eax
309
310 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
311 5d/pop-to-ebp
312 c3/return
313
314 test-get-num-reads-single-digit:
315
316
317 55/push-ebp
318 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
319
320
321
322 68/push _test-stream/imm32
323
324 e8/call clear-stream/disp32
325
326 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
327
328
329 68/push $_test-buffered-file->buffer/imm32
330
331 e8/call clear-stream/disp32
332
333 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
334
335
336 68/push _test-output-stream/imm32
337
338 e8/call clear-stream/disp32
339
340 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
341
342
343 68/push _test-error-stream/imm32
344
345 e8/call clear-stream/disp32
346
347 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
348
349
350
351 68/push "3"/imm32
352 68/push _test-stream/imm32
353
354 e8/call write/disp32
355
356 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
357
358
359 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 8/imm32
360 89/copy 3/mod/direct 0/rm32/eax . . . 4/r32/esp . .
361
362
363 68/push 0x10/imm32/nbytes-of-args-for-get-num
364 50/push-eax/ed
365
366 e8/call tailor-exit-descriptor/disp32
367
368 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
369
370
371
372 68/push _test-buffered-file/imm32
373
374 e8/call get-char/disp32
375
376 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
377
378
379 50/push-eax/ed
380 68/push _test-error-stream/imm32
381 68/push _test-output-stream/imm32
382 68/push _test-buffered-file/imm32
383
384 e8/call get-num/disp32
385
386
387 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
388
389
390 68/push "F - test-get-num-reads-single-digit"/imm32
391 68/push 0x33/imm32
392 b8/copy-to-eax _test-output-stream/imm32
393 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . 0xc/disp8 .
394
395 e8/call check-ints-equal/disp32
396
397 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
398
399 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
400 5d/pop-to-ebp
401 c3/return
402
403 test-get-num-aborts-on-non-digit-in-Look:
404
405
406 55/push-ebp
407 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
408
409
410
411 68/push _test-stream/imm32
412
413 e8/call clear-stream/disp32
414
415 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
416
417
418 68/push $_test-buffered-file->buffer/imm32
419
420 e8/call clear-stream/disp32
421
422 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
423
424
425 68/push _test-output-stream/imm32
426
427 e8/call clear-stream/disp32
428
429 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
430
431
432 68/push _test-error-stream/imm32
433
434 e8/call clear-stream/disp32
435
436 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
437
438
439
440 68/push "3"/imm32
441 68/push _test-stream/imm32
442
443 e8/call write/disp32
444
445 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
446
447
448 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 8/imm32
449 89/copy 3/mod/direct 0/rm32/eax . . . 4/r32/esp . .
450
451
452 68/push 0x10/imm32/nbytes-of-args-for-get-num
453 50/push-eax/ed
454
455 e8/call tailor-exit-descriptor/disp32
456
457 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
458
459
460
461 50/push-eax/ed
462 68/push _test-error-stream/imm32
463 68/push _test-output-stream/imm32
464 68/push _test-buffered-file/imm32
465
466 e8/call get-num/disp32
467
468
469 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
470
471
472
473 68/push "F - test-get-num-aborts-on-non-digit-in-Look"/imm32
474 68/push 2/imm32
475
476 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . 4/disp8 .
477
478 e8/call check-ints-equal/disp32
479
480 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
481
482 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
483 5d/pop-to-ebp
484 c3/return
485
486 test-get-num-reads-multiple-digits:
487
488
489 55/push-ebp
490 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
491
492
493
494 68/push _test-stream/imm32
495
496 e8/call clear-stream/disp32
497
498 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
499
500
501 68/push $_test-buffered-file->buffer/imm32
502
503 e8/call clear-stream/disp32
504
505 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
506
507
508 68/push _test-output-stream/imm32
509
510 e8/call clear-stream/disp32
511
512 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
513
514
515 68/push _test-error-stream/imm32
516
517 e8/call clear-stream/disp32
518
519 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
520
521
522
523 68/push "3456"/imm32
524 68/push _test-stream/imm32
525
526 e8/call write/disp32
527
528 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
529
530
531 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 8/imm32
532 89/copy 3/mod/direct 0/rm32/eax . . . 4/r32/esp . .
533
534
535 68/push 0x10/imm32/nbytes-of-args-for-get-num
536 50/push-eax/ed
537
538 e8/call tailor-exit-descriptor/disp32
539
540 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
541
542
543
544 68/push _test-buffered-file/imm32
545
546 e8/call get-char/disp32
547
548 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
549
550
551 50/push-eax/ed
552 68/push _test-error-stream/imm32
553 68/push _test-output-stream/imm32
554 68/push _test-buffered-file/imm32
555
556 e8/call get-num/disp32
557
558
559 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
560
561
562 68/push "F - test-get-num-reads-multiple-digits"/imm32
563 68/push 0x36353433/imm32
564 b8/copy-to-eax _test-output-stream/imm32
565 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . 0xc/disp8 .
566
567 e8/call check-ints-equal/disp32
568
569 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
570
571 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
572 5d/pop-to-ebp
573 c3/return
574
575 test-get-num-reads-multiple-digits-followed-by-nondigit:
576
577
578 55/push-ebp
579 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
580
581
582
583 68/push _test-stream/imm32
584
585 e8/call clear-stream/disp32
586
587 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
588
589
590 68/push $_test-buffered-file->buffer/imm32
591
592 e8/call clear-stream/disp32
593
594 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
595
596
597 68/push _test-output-stream/imm32
598
599 e8/call clear-stream/disp32
600
601 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
602
603
604 68/push _test-error-stream/imm32
605
606 e8/call clear-stream/disp32
607
608 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
609
610
611
612 68/push "3456 x"/imm32
613 68/push _test-stream/imm32
614
615 e8/call write/disp32
616
617 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
618
619
620 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 8/imm32
621 89/copy 3/mod/direct 0/rm32/eax . . . 4/r32/esp . .
622
623
624 68/push 0x10/imm32/nbytes-of-args-for-get-num
625 50/push-eax/ed
626
627 e8/call tailor-exit-descriptor/disp32
628
629 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
630
631
632
633 68/push _test-buffered-file/imm32
634
635 e8/call get-char/disp32
636
637 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
638
639
640 50/push-eax/ed
641 68/push _test-error-stream/imm32
642 68/push _test-output-stream/imm32
643 68/push _test-buffered-file/imm32
644
645 e8/call get-num/disp32
646
647
648 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
649
650
651 68/push "F - test-get-num-reads-multiple-digits-followed-by-nondigit"/imm32
652 68/push 0x36353433/imm32
653 b8/copy-to-eax _test-output-stream/imm32
654 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . 0xc/disp8 .
655
656 e8/call check-ints-equal/disp32
657
658 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
659
660 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
661 5d/pop-to-ebp
662 c3/return
663
664
665
666
667 expected:
668
669 55/push-ebp
670 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
671
672
673 68/push "Error: "/imm32
674 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
675
676 e8/call write/disp32
677
678 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
679
680
681 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 .
682 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
683
684 e8/call write/disp32
685
686 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
687
688
689 68/push " expected\n"/imm32
690 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
691
692 e8/call write/disp32
693
694 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
695
696
697 68/push 1/imm32
698 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
699
700 e8/call stop/disp32
701
702 $expected:dead-end:
703
704 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
705 5d/pop-to-ebp
706 c3/return
707
708
709 get-char:
710
711 55/push-ebp
712 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
713
714 50/push-eax
715
716
717 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
718
719 e8/call read-byte-buffered/disp32
720
721 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
722
723 89/copy 0/mod/indirect 5/rm32/.disp32 . . 0/r32/eax Look/disp32 .
724 $get-char:end:
725
726 58/pop-to-eax
727
728 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
729 5d/pop-to-ebp
730 c3/return
731
732 is-digit?:
733
734 55/push-ebp
735 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
736
737 b8/copy-to-eax 0/imm32
738
739 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 0x30/imm32
740 7c/jump-if-< $is-digit?:end/disp8
741
742 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 0x39/imm32
743 7f/jump-if-> $is-digit?:end/disp8
744
745 b8/copy-to-eax 1/imm32
746 $is-digit?:end:
747
748 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
749 5d/pop-to-ebp
750 c3/return
751
752 == data
753
754 Look:
755 0/imm32
756
757