https://github.com/akkartik/mu/blob/master/061read-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 == data
272
273
274 _test-buffered-file:
275
276 _test-stream/imm32
277 $_test-buffered-file->buffer:
278
279 0/imm32
280
281 0/imm32
282
283 6/imm32
284
285 00 00 00 00 00 00
286
287 _test-input-stream:
288
289 0/imm32
290
291 0/imm32
292
293 0x100/imm32
294
295 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
296 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
297 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
298 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
299 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
300 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
301 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
302 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
303 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
304 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
305 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
306 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
307 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
308 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
309 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
310 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
311
312
313 _test-input-buffered-file:
314
315 _test-input-stream/imm32
316 $_test-input-buffered-file->buffer:
317
318 0/imm32
319
320 0/imm32
321
322 6/imm32
323
324 00 00 00 00 00 00
325
326