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-lesser $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-not-equal $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
78 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . .
79 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/AL 0x10/disp8 .
80
81 ff 0/subop/increment 1/mod/*+disp8 6/rm32/esi . . . . 8/disp8 .
82 $read-byte-buffered:end:
83
84 5e/pop-to-esi
85 59/pop-to-ecx
86
87 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
88 5d/pop-to-ebp
89 c3/return
90
91
92
93 test-read-byte-buffered-single:
94
95
96
97
98 68/push _test-stream/imm32
99
100 e8/call clear-stream/disp32
101
102 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
103
104
105 68/push _test-buffered-file->buffer/imm32
106
107 e8/call clear-stream/disp32
108
109 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
110
111
112 68/push "Ab"/imm32
113 68/push _test-stream/imm32
114
115 e8/call write/disp32
116
117 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
118
119
120 68/push _test-buffered-file/imm32
121
122 e8/call read-byte-buffered/disp32
123
124 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
125
126
127 68/push "F - test-read-byte-buffered-single"/imm32
128 68/push 0x41/imm32
129 50/push-eax
130
131 e8/call check-ints-equal/disp32
132
133 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
134
135 c3/return
136
137 test-read-byte-buffered-multiple:
138
139
140
141
142 68/push _test-stream/imm32
143
144 e8/call clear-stream/disp32
145
146 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
147
148
149 68/push _test-buffered-file->buffer/imm32
150
151 e8/call clear-stream/disp32
152
153 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
154
155
156 68/push "Ab"/imm32
157 68/push _test-stream/imm32
158
159 e8/call write/disp32
160
161 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
162
163
164 68/push _test-buffered-file/imm32
165
166 e8/call read-byte-buffered/disp32
167
168 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
169
170
171 68/push _test-buffered-file/imm32
172
173 e8/call read-byte-buffered/disp32
174
175 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
176
177
178 68/push "F - test-read-byte-buffered-multiple"/imm32
179 68/push 0x62/imm32
180 50/push-eax
181
182 e8/call check-ints-equal/disp32
183
184 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
185
186 c3/return
187
188 test-read-byte-buffered-end-of-file:
189
190
191
192
193 68/push _test-stream/imm32
194
195 e8/call clear-stream/disp32
196
197 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
198
199
200 68/push _test-buffered-file->buffer/imm32
201
202 e8/call clear-stream/disp32
203
204 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
205
206
207 68/push _test-buffered-file/imm32
208
209 e8/call read-byte-buffered/disp32
210
211 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
212
213
214 68/push "F - test-read-byte-buffered-end-of-file"/imm32
215 68/push 0xffffffff/imm32/Eof
216 50/push-eax
217
218 e8/call check-ints-equal/disp32
219
220 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
221
222 c3/return
223
224 test-read-byte-buffered-refills-buffer:
225
226
227
228
229 68/push _test-stream/imm32
230
231 e8/call clear-stream/disp32
232
233 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
234
235
236 68/push _test-buffered-file->buffer/imm32
237
238 e8/call clear-stream/disp32
239
240 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
241
242
243 68/push "Abcdefgh"/imm32
244 68/push _test-stream/imm32
245
246 e8/call write/disp32
247
248 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
249
250
251 b8/copy-to-eax _test-buffered-file/imm32
252 c7 0/subop/copy 1/mod/*+disp8 0/rm32/eax . . . . 8/disp8 6/imm32
253
254
255 68/push _test-buffered-file/imm32
256
257 e8/call read-byte-buffered/disp32
258
259 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
260
261
262 68/push "F - test-read-byte-buffered-refills-buffer"/imm32
263 68/push 0x41/imm32
264 50/push-eax
265
266 e8/call check-ints-equal/disp32
267
268 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
269
270 c3/return
271
272 == data
273
274
275 _test-buffered-file:
276
277 _test-stream/imm32
278 _test-buffered-file->buffer:
279
280 0/imm32
281
282 0/imm32
283
284 6/imm32
285
286 00 00 00 00 00 00
287
288 _test-input-stream:
289
290 0/imm32
291
292 0/imm32
293
294 0x100/imm32
295
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 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
312
313
314 _test-input-buffered-file:
315
316 _test-input-stream/imm32
317 _test-input-buffered-file->buffer:
318
319 0/imm32
320
321 0/imm32
322
323 6/imm32
324
325 00 00 00 00 00 00
326
327