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-addr>= $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-addr>= $_buffer-4:end/disp8
169
170 39/compare 3/mod/direct 7/rm32/edi . . . 2/r32/edx . .
171 73/jump-if-addr>= $_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 _read:
199
200 55/push-ebp
201 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
202
203 51/push-ecx
204 52/push-edx
205 53/push-ebx
206 56/push-esi
207
208 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0xc/disp8 .
209
210 8b/copy 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . .
211
212 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 2/r32/edx 8/disp8 .
213
214
215 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 3/r32/ebx 8/disp8 .
216
217 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 1/r32/ecx 0xc/disp8 .
218
219 29/subtract 3/mod/direct 2/rm32/edx . . . 0/r32/eax . .
220
221 b8/copy-to-eax 3/imm32/read
222 cd/syscall 0x80/imm8
223
224 01/add 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . .
225 $_read:end:
226
227 5e/pop-to-esi
228 5b/pop-to-ebx
229 5a/pop-to-edx
230 59/pop-to-ecx
231
232 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
233 5d/pop-to-ebp
234 c3/return
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259 test-read-single:
260
261
262
263 68/push _test-stream/imm32
264
265 e8/call clear-stream/disp32
266
267 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
268
269
270 68/push _test-tmp-stream/imm32
271
272 e8/call clear-stream/disp32
273
274 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
275
276
277 68/push "Ab"/imm32
278 68/push _test-stream/imm32
279
280 e8/call write/disp32
281
282 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
283
284
285 68/push _test-tmp-stream/imm32
286 68/push _test-stream/imm32
287
288 e8/call read/disp32
289
290 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
291
292
293 68/push "F - test-read-single: return value"/imm32
294 68/push 2/imm32
295 50/push-eax
296
297 e8/call check-ints-equal/disp32
298
299 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
300
301
302 68/push "F - test-read-single"/imm32
303 68/push "Ab"/imm32
304 68/push _test-tmp-stream/imm32
305
306 e8/call check-stream-equal/disp32
307
308 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
309
310 c3/return
311
312 test-read-is-stateful:
313
314
315
316 68/push _test-stream/imm32
317
318 e8/call clear-stream/disp32
319
320 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
321
322
323 68/push _test-tmp-stream/imm32
324
325 e8/call clear-stream/disp32
326
327 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
328
329
330 68/push "C"/imm32
331 68/push _test-stream/imm32
332
333 e8/call write/disp32
334
335 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
336
337
338 68/push _test-tmp-stream/imm32
339 68/push _test-stream/imm32
340
341 e8/call read/disp32
342
343 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
344
345
346 68/push "D"/imm32
347 68/push _test-stream/imm32
348
349 e8/call write/disp32
350
351 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
352
353
354 68/push _test-tmp-stream/imm32
355 68/push _test-stream/imm32
356
357 e8/call read/disp32
358
359 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
360
361
362 68/push "F - test-read-is-stateful"/imm32
363 68/push "CD"/imm32
364 68/push _test-tmp-stream/imm32
365
366 e8/call check-stream-equal/disp32
367
368 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
369
370 c3/return
371
372 test-read-returns-0-on-end-of-file:
373
374
375
376
377 68/push _test-stream/imm32
378
379 e8/call clear-stream/disp32
380
381 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
382
383
384 68/push _test-tmp-stream/imm32
385
386 e8/call clear-stream/disp32
387
388 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
389
390
391 68/push "Ab"/imm32
392 68/push _test-stream/imm32
393
394 e8/call write/disp32
395
396 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
397
398
399
400 68/push _test-tmp-stream/imm32
401 68/push _test-stream/imm32
402
403 e8/call read/disp32
404
405 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
406
407
408
409 68/push _test-tmp-stream/imm32
410 68/push _test-stream/imm32
411
412 e8/call read/disp32
413
414 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
415
416
417 68/push "F - test-read-returns-0-on-end-of-file"/imm32
418 68/push 0/imm32
419 50/push-eax
420
421 e8/call check-ints-equal/disp32
422
423 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
424
425 c3/return
426
427 == data
428
429 _test-tmp-stream:
430
431 0/imm32
432
433 0/imm32
434
435 8/imm32
436
437 00 00 00 00 00 00 00 00
438
439