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