https://github.com/akkartik/mu/blob/master/subx/apps/crenshaw2-1.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
34
35
36
37
38
39 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
40
41
42 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0/disp8 1/imm32
43 7e/jump-if-lesser-or-equal $run-main/disp8
44
45
46 68/push "test"/imm32
47 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x8/disp8
48
49 e8/call kernel-string-equal/disp32
50
51 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
52
53 3d/compare-EAX 1/imm32
54 75/jump-if-not-equal $run-main/disp8
55
56 e8/call run-tests/disp32
57 8b/copy 0/mod/indirect 5/rm32/.disp32 3/r32/EBX Num-test-failures/disp32
58 eb/jump $main:end/disp8
59 $run-main:
60
61
62 81 5/subop/subtract 3/mod/direct 4/rm32/ESP 8/imm32
63 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none 0/r32/EAX
64
65
66 c7/copy 0/mod/direct 0/rm32/EAX 0/imm32
67
68
69 50/push-EAX/ed
70 68/push 2/imm32/stderr
71 68/push 1/imm32/stdout
72 68/push Stdin/imm32
73
74 e8/call compile/disp32
75
76 81 0/subop/add 3/mod/direct 4/rm32/ESP 0x10/imm32
77
78 bb/copy-to-EBX 0/imm32
79 $main:end:
80 b8/copy-to-EAX 1/imm32/exit
81 cd/syscall 0x80/imm8
82
83
84 compile:
85
86 55/push-EBP
87 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
88
89 50/push-EAX
90 51/push-ECX
91
92
93
94 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 8/disp8
95
96 e8/call get-char/disp32
97
98 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
99
100
101
102
103
104 81 5/subop/subtract 3/mod/direct 4/rm32/ESP 0x13/imm32
105 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none 1/r32/ECX
106
107
108 c7/copy 1/mod/*+disp8 1/rm32/ECX 8/disp8 7/imm32
109
110
111 51/push-ECX
112
113 e8/call clear-stream/disp32
114
115 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
116
117
118
119 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x14/disp8
120 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x10/disp8
121 51/push-ECX/num
122 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 8/disp8
123
124 e8/call get-num/disp32
125
126 81 0/subop/add 3/mod/direct 4/rm32/ESP 0x10/imm32
127
128
129
130
131
132
133
134 68/push "bb/copy-to-EBX "/imm32
135 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
136
137 e8/call write/disp32
138
139 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
140
141
142 51/push-ECX/num
143 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
144
145 e8/call write-stream/disp32
146
147 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
148
149
150 68/push Newline/imm32
151 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
152
153 e8/call write/disp32
154
155 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
156
157
158 68/push "b8/copy-to-EAX 1/imm32/exit"/imm32
159 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
160
161 e8/call write/disp32
162
163 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
164
165
166 68/push Newline/imm32
167 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
168
169 e8/call write/disp32
170
171 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
172
173
174 68/push "cd/syscall 0x80/imm8"/imm32
175 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
176
177 e8/call write/disp32
178
179 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
180
181
182 68/push Newline/imm32
183 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
184
185 e8/call write/disp32
186
187 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
188
189 59/pop-to-ECX
190 58/pop-to-EAX
191
192 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
193 5d/pop-to-EBP
194 c3/return
195
196
197
198
199 get-num:
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221 55/push-EBP
222 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
223
224
225
226 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 Look/disp32
227
228 e8/call is-digit?/disp32
229
230 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
231
232 3d/compare-EAX 0/imm32
233 75/jump-if-not-equal $get-num:main/disp8
234
235
236 68/push "integer"/imm32
237 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x10/disp8
238 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x14/disp8
239
240 e8/call expected/disp32
241
242 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
243 $get-num:main:
244
245
246 50/push-EAX
247 51/push-ECX
248 52/push-EDX
249 53/push-EBX
250 56/push-ESI
251 57/push-EDI
252
253
254 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 6/r32/ESI 8/disp8
255
256 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 7/r32/EDI 0xc/disp8
257
258 8b/copy 0/mod/indirect 7/rm32/EDI 1/r32/ECX
259
260 8b/copy 1/mod/*+disp8 7/rm32/EDI 2/r32/EDX 8/disp8
261
262 3b/compare 3/mod/direct 1/rm32/ECX 2/r32/EDX
263 7d/jump-if-lesser $get-num:stage2/disp8
264
265
266 68/push "get-num: too many digits in number"/imm32
267 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x10/disp8
268 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x14/disp8
269
270 e8/call error/disp32
271
272 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
273 $get-num: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 $get-num:loop-end:
288
289 89/copy 0/mod/indirect 7/rm32/EDI 1/r32/ECX
290
291 5f/pop-to-EDI
292 5e/pop-to-ESI
293 5b/pop-to-EBX
294 5a/pop-to-EDX
295 59/pop-to-ECX
296 58/pop-to-EAX
297
298 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
299 5d/pop-to-EBP
300 c3/return
301
302 test-get-num-reads-single-digit:
303
304
305 55/push-EBP
306 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
307
308
309
310 68/push _test-stream/imm32
311
312 e8/call clear-stream/disp32
313
314 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
315
316
317 b8/copy-to-EAX _test-buffered-file/imm32
318 05/add-to-EAX 4/imm32
319 50/push-EAX
320
321 e8/call clear-stream/disp32
322
323 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
324
325
326 68/push _test-output-stream/imm32
327
328 e8/call clear-stream/disp32
329
330 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
331
332
333 68/push _test-error-stream/imm32
334
335 e8/call clear-stream/disp32
336
337 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
338
339
340
341 68/push "3"/imm32
342 68/push _test-stream/imm32
343
344 e8/call write/disp32
345
346 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
347
348
349 81 5/subop/subtract 3/mod/direct 4/rm32/ESP 8/imm32
350 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none 0/r32/EAX
351
352
353 68/push 0x10/imm32/nbytes-of-args-for-get-num
354 50/push-EAX/ed
355
356 e8/call tailor-exit-descriptor/disp32
357
358 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
359
360
361
362 68/push _test-buffered-file/imm32
363
364 e8/call get-char/disp32
365
366 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
367
368
369 50/push-EAX/ed
370 68/push _test-error-stream/imm32
371 68/push _test-output-stream/imm32
372 68/push _test-buffered-file/imm32
373
374 e8/call get-num/disp32
375
376
377 81 0/subop/add 3/mod/direct 4/rm32/ESP 0x10/imm32
378
379
380 68/push "F - test-get-num-reads-single-digit"/imm32
381 68/push 0x33/imm32
382 b8/copy-to-EAX _test-output-stream/imm32
383 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX 0xc/disp8
384
385 e8/call check-ints-equal/disp32
386
387 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
388
389 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
390 5d/pop-to-EBP
391 c3/return
392
393 test-get-num-aborts-on-non-digit-in-Look:
394
395
396 55/push-EBP
397 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
398
399
400
401 68/push _test-stream/imm32
402
403 e8/call clear-stream/disp32
404
405 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
406
407
408 b8/copy-to-EAX _test-buffered-file/imm32
409 05/add-to-EAX 4/imm32
410 50/push-EAX
411
412 e8/call clear-stream/disp32
413
414 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
415
416
417 68/push _test-output-stream/imm32
418
419 e8/call clear-stream/disp32
420
421 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
422
423
424 68/push _test-error-stream/imm32
425
426 e8/call clear-stream/disp32
427
428 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
429
430
431
432 68/push "3"/imm32
433 68/push _test-stream/imm32
434
435 e8/call write/disp32
436
437 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
438
439
440 81 5/subop/subtract 3/mod/direct 4/rm32/ESP 8/imm32
441 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none 0/r32/EAX
442
443
444 68/push 0x10/imm32/nbytes-of-args-for-get-num
445 50/push-EAX/ed
446
447 e8/call tailor-exit-descriptor/disp32
448
449 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
450
451
452
453 50/push-EAX/ed
454 68/push _test-error-stream/imm32
455 68/push _test-output-stream/imm32
456 68/push _test-buffered-file/imm32
457
458 e8/call get-num/disp32
459
460
461 81 0/subop/add 3/mod/direct 4/rm32/ESP 0x10/imm32
462
463
464
465 68/push "F - test-get-num-aborts-on-non-digit-in-Look"/imm32
466 68/push 2/imm32
467
468 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX 4/disp8
469
470 e8/call check-ints-equal/disp32
471
472 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
473
474 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
475 5d/pop-to-EBP
476 c3/return
477
478
479
480
481 expected:
482
483 55/push-EBP
484 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
485
486
487 68/push "Error: "/imm32
488 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
489
490 e8/call write/disp32
491
492 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
493
494
495 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x10/disp8
496 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
497
498 e8/call write/disp32
499
500 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
501
502
503 68/push " expected"/imm32
504 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
505
506 e8/call write/disp32
507
508 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
509
510
511 68/push Newline/imm32
512 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
513
514 e8/call write/disp32
515
516 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
517
518
519 68/push 1/imm32
520 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 8/disp8
521
522 e8/call stop/disp32
523
524
525 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
526 5d/pop-to-EBP
527 c3/return
528
529
530 error:
531
532 55/push-EBP
533 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
534
535
536 68/push "Error: "/imm32
537 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
538
539 e8/call write/disp32
540
541 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
542
543
544 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x10/disp8
545 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
546
547 e8/call write/disp32
548
549 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
550
551
552 68/push Newline/imm32
553 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
554
555 e8/call write/disp32
556
557 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
558
559
560 68/push 1/imm32
561 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 8/disp8
562
563 e8/call stop/disp32
564
565
566 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
567 5d/pop-to-EBP
568 c3/return
569
570
571 get-char:
572
573 55/push-EBP
574 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
575
576 50/push-EAX
577
578
579 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x8/disp8
580
581 e8/call read-byte/disp32
582
583 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
584
585 89/copy 0/mod/indirect 5/rm32/.disp32 0/r32/EAX Look/disp32
586
587 58/pop-to-EAX
588
589 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
590 5d/pop-to-EBP
591 c3/return
592
593 is-digit?:
594
595 55/push-EBP
596 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
597
598 b8/copy-to-EAX 0/imm32
599
600 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x8/disp8 0x30/imm32
601 7c/jump-if-lesser $is-digit?:end/disp8
602
603 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0x8/disp8 0x39/imm32
604 7f/jump-if-greater $is-digit?:end/disp8
605
606 b8/copy-to-EAX 1/imm32
607 $is-digit?:end:
608
609 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
610 5d/pop-to-EBP
611 c3/return
612
613 == data
614
615 Look:
616 00 00 00 00
617
618 _test-output-stream:
619
620 00 00 00 00
621
622 00 00 00 00
623
624 08 00 00 00
625
626 00 00 00 00 00 00 00 00
627
628 _test-error-stream:
629
630 00 00 00 00
631
632 00 00 00 00
633
634 08 00 00 00
635
636 00 00 00 00 00 00 00 00
637
638