https://github.com/akkartik/mu/blob/master/subx/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 7d/jump-if-greater-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 7d/jump-if-greater-or-equal $_buffer-4:end/disp8
169
170 39/compare 3/mod/direct 7/rm32/EDI . . . 2/r32/EDX . .
171 7d/jump-if-greater-or-equal $_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 EAX"/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