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
18 0/imm32
19
20 0/imm32
21
22 8/imm32
23
24 00 00 00 00 00 00 00 00
25
26
27
28
29 == code
30
31
32
33
34
35
36 read-byte-buffered:
37
38 55/push-EBP
39 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
40
41 51/push-ECX
42 56/push-ESI
43
44 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 8/disp8 .
45
46 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 8/disp8 .
47
48 3b/compare 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
49 7c/jump-if-lesser $read-byte-buffered:from-stream/disp8
50
51
52 8d/copy-address 1/mod/*+disp8 6/rm32/ESI . . . 0/r32/EAX 4/disp8 .
53 50/push-EAX
54
55 e8/call clear-stream/disp32
56
57 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
58
59 31/xor 3/mod/direct 1/rm32/ECX . . . 1/r32/ECX . .
60
61
62 50/push-EAX
63 ff 6/subop/push 0/mod/indirect 6/rm32/ESI . . . . . .
64
65 e8/call read/disp32
66
67 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
68
69 3d/compare-EAX-and 0/imm32
70 75/jump-if-not-equal $read-byte-buffered:from-stream/disp8
71 b8/copy-to-EAX 0xffffffff/imm32/Eof
72 eb/jump $read-byte-buffered:end/disp8
73 $read-byte-buffered:from-stream:
74
75
76 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . .
77 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/AL 0x10/disp8 .
78
79 ff 0/subop/increment 1/mod/*+disp8 6/rm32/ESI . . . . 8/disp8 .
80 $read-byte-buffered:end:
81
82 5e/pop-to-ESI
83 59/pop-to-ECX
84
85 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
86 5d/pop-to-EBP
87 c3/return
88
89
90
91 test-read-byte-buffered-single:
92
93
94
95
96 68/push _test-stream/imm32
97
98 e8/call clear-stream/disp32
99
100 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
101
102
103 b8/copy-to-EAX _test-buffered-file/imm32
104 05/add-to-EAX 4/imm32
105 50/push-EAX
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 b8/copy-to-EAX _test-buffered-file/imm32
150 05/add-to-EAX 4/imm32
151 50/push-EAX
152
153 e8/call clear-stream/disp32
154
155 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
156
157
158 68/push "Ab"/imm32
159 68/push _test-stream/imm32
160
161 e8/call write/disp32
162
163 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
164
165
166 68/push _test-buffered-file/imm32
167
168 e8/call read-byte-buffered/disp32
169
170 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
171
172
173 68/push _test-buffered-file/imm32
174
175 e8/call read-byte-buffered/disp32
176
177 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
178
179
180 68/push "F - test-read-byte-buffered-multiple"/imm32
181 68/push 0x62/imm32
182 50/push-EAX
183
184 e8/call check-ints-equal/disp32
185
186 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
187
188 c3/return
189
190 test-read-byte-buffered-end-of-file:
191
192
193
194
195 68/push _test-stream/imm32
196
197 e8/call clear-stream/disp32
198
199 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
200
201
202 b8/copy-to-EAX _test-buffered-file/imm32
203 05/add-to-EAX 4/imm32
204 50/push-EAX
205
206 e8/call clear-stream/disp32
207
208 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
209
210
211 68/push _test-buffered-file/imm32
212
213 e8/call read-byte-buffered/disp32
214
215 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
216
217
218 68/push "F - test-read-byte-buffered-end-of-file"/imm32
219 68/push 0xffffffff/imm32/Eof
220 50/push-EAX
221
222 e8/call check-ints-equal/disp32
223
224 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
225
226 c3/return
227
228 test-read-byte-buffered-refills-buffer:
229
230
231
232
233 68/push _test-stream/imm32
234
235 e8/call clear-stream/disp32
236
237 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
238
239
240 b8/copy-to-EAX _test-buffered-file/imm32
241 05/add-to-EAX 4/imm32
242 50/push-EAX
243
244 e8/call clear-stream/disp32
245
246 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
247
248
249 68/push "Abcdefgh"/imm32
250 68/push _test-stream/imm32
251
252 e8/call write/disp32
253
254 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
255
256
257 b8/copy-to-EAX _test-buffered-file/imm32
258 c7 0/subop/copy 1/mod/*+disp8 0/rm32/EAX . . . . 8/disp8 6/imm32
259
260
261 68/push _test-buffered-file/imm32
262
263 e8/call read-byte-buffered/disp32
264
265 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
266
267
268 68/push "F - test-read-byte-buffered-refills-buffer"/imm32
269 68/push 0x41/imm32
270 50/push-EAX
271
272 e8/call check-ints-equal/disp32
273
274 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
275
276 c3/return
277
278 == data
279
280
281 _test-buffered-file:
282
283 _test-stream/imm32
284
285 0/imm32
286
287 0/imm32
288
289 6/imm32
290
291 00 00 00 00 00 00
292
293 _test-input-stream:
294
295 0/imm32
296
297 0/imm32
298
299 0x100/imm32
300
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 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
313 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
314 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
315 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
316 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
317
318
319 _test-input-buffered-file:
320
321 _test-input-stream/imm32
322
323 0/imm32
324
325 0/imm32
326
327 6/imm32
328
329 00 00 00 00 00 00
330
331