https://github.com/akkartik/mu/blob/master/060read.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 == code
44
45
46
47
48 read:
49
50 55/push-ebp
51 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
52
53 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 0x08000000/imm32
54 73/jump-if-greater-unsigned-or-equal $read:fake/disp8
55
56 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
57 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
58
59 e8/call _read/disp32
60
61 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
62
63 eb/jump $read:end/disp8
64 $read:fake:
65
66
67 56/push-esi
68 57/push-edi
69
70 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 .
71
72 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 .
73
74
75
76 8b/copy 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . .
77 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 0/r32/eax 0xc/disp8 .
78 50/push-eax
79
80 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 .
81 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 0/r32/eax 0xc/disp8 .
82 50/push-eax
83
84 8b/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 8/disp8 .
85 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 0/index/eax . 0/r32/eax 0xc/disp8 .
86 50/push-eax
87
88 8b/copy 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . .
89 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 0/index/eax . 0/r32/eax 0xc/disp8 .
90 50/push-eax
91
92 e8/call _buffer-4/disp32
93
94 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
95
96 01/add 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . .
97
98 01/add 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 .
99
100 5f/pop-to-edi
101 5e/pop-to-esi
102 $read:end:
103
104 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
105 5d/pop-to-ebp
106 c3/return
107
108
109
110
111
112
113 _buffer-3:
114
115 55/push-ebp
116 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
117
118 51/push-ecx
119
120
121 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 0/r32/eax 0x10/disp8 .
122 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
123 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
124 51/push-ecx
125
126 8d/copy-address 1/mod/*+disp8 0/rm32/eax . . . 1/r32/ecx 4/disp8 .
127 51/push-ecx
128
129 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
130
131 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
132
133 e8/call _buffer-4/disp32
134
135 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
136 $_buffer-3:end:
137
138 59/pop-to-ecx
139
140 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
141 5d/pop-to-ebp
142 c3/return
143
144
145 _buffer-4:
146
147 55/push-ebp
148 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
149
150 51/push-ecx
151 52/push-edx
152 53/push-ebx
153 56/push-esi
154 57/push-edi
155
156 b8/copy-to-eax 0/imm32
157
158 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 8/disp8 .
159
160 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 2/r32/edx 0xc/disp8 .
161
162 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0x10/disp8 .
163
164 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0x14/disp8 .
165 $_buffer-4:loop:
166
167 39/compare 3/mod/direct 6/rm32/esi . . . 1/r32/ecx . .
168 73/jump-if-greater-or-equal-unsigned $_buffer-4:end/disp8
169
170 39/compare 3/mod/direct 7/rm32/edi . . . 2/r32/edx . .
171 73/jump-if-greater-or-equal-unsigned $_buffer-4:end/disp8
172
173 8a/copy-byte 0/mod/indirect 6/rm32/esi . . . 3/r32/BL . .
174 88/copy-byte 0/mod/indirect 7/rm32/edi . . . 3/r32/BL . .
175
176 40/increment-eax
177
178 46/increment-esi
179
180 47/increment-edi
181 eb/jump $_buffer-4:loop/disp8
182 $_buffer-4:end:
183
184 5f/pop-to-edi
185 5e/pop-to-esi
186 5b/pop-to-ebx
187 5a/pop-to-edx
188 59/pop-to-ecx
189
190 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
191 5d/pop-to-ebp
192 c3/return
193
194
195
196
197
198
199 _read:
200
201 55/push-ebp
202 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
203
204 51/push-ecx
205 52/push-edx
206 53/push-ebx
207 56/push-esi
208
209 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0xc/disp8 .
210
211 8b/copy 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . .
212
213 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 2/r32/edx 8/disp8 .
214
215
216 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 3/r32/ebx 8/disp8 .
217
218 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 1/r32/ecx 0xc/disp8 .
219
220 29/subtract 3/mod/direct 2/rm32/edx . . . 0/r32/eax . .
221
222 b8/copy-to-eax 3/imm32/read
223 cd/syscall 0x80/imm8
224
225 01/add 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . .
226 $_read:end:
227
228 5e/pop-to-esi
229 5b/pop-to-ebx
230 5a/pop-to-edx
231 59/pop-to-ecx
232
233 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
234 5d/pop-to-ebp
235 c3/return
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260 test-read-single:
261
262
263
264 68/push _test-stream/imm32
265
266 e8/call clear-stream/disp32
267
268 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
269
270
271 68/push _test-tmp-stream/imm32
272
273 e8/call clear-stream/disp32
274
275 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
276
277
278 68/push "Ab"/imm32
279 68/push _test-stream/imm32
280
281 e8/call write/disp32
282
283 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
284
285
286 68/push _test-tmp-stream/imm32
287 68/push _test-stream/imm32
288
289 e8/call read/disp32
290
291 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
292
293
294 68/push "F - test-read-single: return value"/imm32
295 68/push 2/imm32
296 50/push-eax
297
298 e8/call check-ints-equal/disp32
299
300 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
301
302
303 68/push "F - test-read-single"/imm32
304 68/push "Ab"/imm32
305 68/push _test-tmp-stream/imm32
306
307 e8/call check-stream-equal/disp32
308
309 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
310
311 c3/return
312
313 test-read-is-stateful:
314
315
316
317 68/push _test-stream/imm32
318
319 e8/call clear-stream/disp32
320
321 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
322
323
324 68/push _test-tmp-stream/imm32
325
326 e8/call clear-stream/disp32
327
328 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
329
330
331 68/push "C"/imm32
332 68/push _test-stream/imm32
333
334 e8/call write/disp32
335
336 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
337
338
339 68/push _test-tmp-stream/imm32
340 68/push _test-stream/imm32
341
342 e8/call read/disp32
343
344 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
345
346
347 68/push "D"/imm32
348 68/push _test-stream/imm32
349
350 e8/call write/disp32
351
352 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
353
354
355 68/push _test-tmp-stream/imm32
356 68/push _test-stream/imm32
357
358 e8/call read/disp32
359
360 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
361
362
363 68/push "F - test-read-is-stateful"/imm32
364 68/push "CD"/imm32
365 68/push _test-tmp-stream/imm32
366
367 e8/call check-stream-equal/disp32
368
369 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
370
371 c3/return
372
373 test-read-returns-0-on-end-of-file:
374
375
376
377
378 68/push _test-stream/imm32
379
380 e8/call clear-stream/disp32
381
382 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
383
384
385 68/push _test-tmp-stream/imm32
386
387 e8/call clear-stream/disp32
388
389 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
390
391
392 68/push "Ab"/imm32
393 68/push _test-stream/imm32
394
395 e8/call write/disp32
396
397 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
398
399
400
401 68/push _test-tmp-stream/imm32
402 68/push _test-stream/imm32
403
404 e8/call read/disp32
405
406 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
407
408
409
410 68/push _test-tmp-stream/imm32
411 68/push _test-stream/imm32
412
413 e8/call read/disp32
414
415 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
416
417
418 68/push "F - test-read-returns-0-on-end-of-file"/imm32
419 68/push 0/imm32
420 50/push-eax
421
422 e8/call check-ints-equal/disp32
423
424 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
425
426 c3/return
427
428 == data
429
430 _test-tmp-stream:
431
432 0/imm32
433
434 0/imm32
435
436 8/imm32
437
438 00 00 00 00 00 00 00 00
439
440