https://github.com/akkartik/mu/blob/master/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 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-lesser-or-equal $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-equal $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 . . . . . 4/imm32
125
126
127
128 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x14/disp8 .
129 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 .
130 51/push-ecx/num
131 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
132
133 e8/call get-num/disp32
134
135 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
136
137
138
139
140
141
142
143 68/push "bb/copy-to-ebx "/imm32
144 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
145
146 e8/call write/disp32
147
148 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
149
150
151 51/push-ecx/num
152 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
153
154 e8/call write-stream/disp32
155
156 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
157
158
159 68/push Newline/imm32
160 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
161
162 e8/call write/disp32
163
164 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
165
166
167 68/push "b8/copy-to-eax 1/imm32/exit\n"/imm32
168 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
169
170 e8/call write/disp32
171
172 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
173
174
175 68/push "cd/syscall 0x80/imm8\n"/imm32
176 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
177
178 e8/call write/disp32
179
180 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
181 $compile:end:
182
183 59/pop-to-ecx
184 58/pop-to-eax
185
186 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
187 5d/pop-to-ebp
188 c3/return
189
190
191
192
193
194 get-num:
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215 55/push-ebp
216 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
217
218
219
220 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Look/disp32 .
221
222 e8/call is-digit?/disp32
223
224 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
225
226 3d/compare-eax-and 0/imm32/false
227 75/jump-if-not-equal $get-num:main/disp8
228
229
230 68/push "integer"/imm32
231 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 .
232 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x14/disp8 .
233
234 e8/call expected/disp32
235
236 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
237 $get-num:main:
238
239
240 50/push-eax
241 51/push-ecx
242 52/push-edx
243 53/push-ebx
244 56/push-esi
245 57/push-edi
246
247
248 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 .
249
250 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 .
251
252 8b/copy 0/mod/indirect 7/rm32/edi . . . 1/r32/ecx . .
253
254 8b/copy 1/mod/*+disp8 7/rm32/edi . . . 2/r32/edx 8/disp8 .
255 $get-num:loop:
256
257 39/compare 3/mod/direct 2/rm32/edx . . . 1/r32/ecx . .
258 7d/jump-if-lesser $get-num:stage2/disp8
259
260
261 68/push "get-num: too many digits in number"/imm32
262 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 .
263 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x14/disp8 .
264
265 e8/call error/disp32
266
267 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
268 $get-num:stage2:
269
270 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 1/index/ecx . 3/r32/ebx 0xc/disp8 .
271 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 0/r32/eax Look/disp32 .
272 88/copy-byte 0/mod/indirect 3/rm32/ebx . . . 0/r32/AL . .
273
274 41/increment-ecx
275
276
277 56/push-esi
278
279 e8/call get-char/disp32
280
281 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
282 $get-num:loop-end:
283
284 89/copy 0/mod/indirect 7/rm32/edi . . . 1/r32/ecx . .
285 $get-num:end:
286
287 5f/pop-to-edi
288 5e/pop-to-esi
289 5b/pop-to-ebx
290 5a/pop-to-edx
291 59/pop-to-ecx
292 58/pop-to-eax
293
294 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
295 5d/pop-to-ebp
296 c3/return
297
298 test-get-num-reads-single-digit:
299
300
301 55/push-ebp
302 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
303
304
305
306 68/push _test-stream/imm32
307
308 e8/call clear-stream/disp32
309
310 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
311
312
313 68/push $_test-buffered-file->buffer/imm32
314
315 e8/call clear-stream/disp32
316
317 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
318
319
320 68/push _test-output-stream/imm32
321
322 e8/call clear-stream/disp32
323
324 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
325
326
327 68/push _test-error-stream/imm32
328
329 e8/call clear-stream/disp32
330
331 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
332
333
334
335 68/push "3"/imm32
336 68/push _test-stream/imm32
337
338 e8/call write/disp32
339
340 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
341
342
343 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 8/imm32
344 89/copy 3/mod/direct 0/rm32/eax . . . 4/r32/esp . .
345
346
347 68/push 0x10/imm32/nbytes-of-args-for-get-num
348 50/push-eax/ed
349
350 e8/call tailor-exit-descriptor/disp32
351
352 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
353
354
355
356 68/push _test-buffered-file/imm32
357
358 e8/call get-char/disp32
359
360 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
361
362
363 50/push-eax/ed
364 68/push _test-error-stream/imm32
365 68/push _test-output-stream/imm32
366 68/push _test-buffered-file/imm32
367
368 e8/call get-num/disp32
369
370
371 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
372
373
374 68/push "F - test-get-num-reads-single-digit"/imm32
375 68/push 0x33/imm32
376 b8/copy-to-eax _test-output-stream/imm32
377 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . 0xc/disp8 .
378
379 e8/call check-ints-equal/disp32
380
381 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
382
383 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
384 5d/pop-to-ebp
385 c3/return
386
387 test-get-num-aborts-on-non-digit-in-Look:
388
389
390 55/push-ebp
391 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
392
393
394
395 68/push _test-stream/imm32
396
397 e8/call clear-stream/disp32
398
399 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
400
401
402 68/push $_test-buffered-file->buffer/imm32
403
404 e8/call clear-stream/disp32
405
406 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
407
408
409 68/push _test-output-stream/imm32
410
411 e8/call clear-stream/disp32
412
413 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
414
415
416 68/push _test-error-stream/imm32
417
418 e8/call clear-stream/disp32
419
420 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
421
422
423
424 68/push "3"/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 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 8/imm32
433 89/copy 3/mod/direct 0/rm32/eax . . . 4/r32/esp . .
434
435
436 68/push 0x10/imm32/nbytes-of-args-for-get-num
437 50/push-eax/ed
438
439 e8/call tailor-exit-descriptor/disp32
440
441 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
442
443
444
445 50/push-eax/ed
446 68/push _test-error-stream/imm32
447 68/push _test-output-stream/imm32
448 68/push _test-buffered-file/imm32
449
450 e8/call get-num/disp32
451
452
453 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
454
455
456
457 68/push "F - test-get-num-aborts-on-non-digit-in-Look"/imm32
458 68/push 2/imm32
459
460 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . 4/disp8 .
461
462 e8/call check-ints-equal/disp32
463
464 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
465
466 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
467 5d/pop-to-ebp
468 c3/return
469
470
471
472
473 expected:
474
475 55/push-ebp
476 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
477
478
479 68/push "Error: "/imm32
480 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
481
482 e8/call write/disp32
483
484 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
485
486
487 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 .
488 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 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 68/push " expected\n"/imm32
496 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 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 1/imm32
504 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
505
506 e8/call stop/disp32
507
508 $expected:dead-end:
509
510 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
511 5d/pop-to-ebp
512 c3/return
513
514
515 get-char:
516
517 55/push-ebp
518 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
519
520 50/push-eax
521
522
523 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
524
525 e8/call read-byte-buffered/disp32
526
527 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
528
529 89/copy 0/mod/indirect 5/rm32/.disp32 . . 0/r32/eax Look/disp32 .
530 $get-char:end:
531
532 58/pop-to-eax
533
534 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
535 5d/pop-to-ebp
536 c3/return
537
538 is-digit?:
539
540 55/push-ebp
541 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
542
543 b8/copy-to-eax 0/imm32
544
545 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 0x30/imm32
546 7c/jump-if-lesser $is-digit?:end/disp8
547
548 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 0x39/imm32
549 7f/jump-if-greater $is-digit?:end/disp8
550
551 b8/copy-to-eax 1/imm32
552 $is-digit?:end:
553
554 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
555 5d/pop-to-ebp
556 c3/return
557
558 == data
559
560 Look:
561 0/imm32
562
563