https://github.com/akkartik/mu/blob/master/subx/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
37
38
39
40
41
42
43
44 read-byte:
45
46 55/push-EBP
47 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
48
49 51/push-ECX
50 56/push-ESI
51
52 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 8/disp8 .
53
54 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 8/disp8 .
55
56 3b/compare 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
57 7c/jump-if-lesser $read-byte:from-stream/disp8
58
59
60 8d/copy-address 1/mod/*+disp8 6/rm32/ESI . . . 0/r32/EAX 4/disp8 .
61 50/push-EAX
62
63 e8/call clear-stream/disp32
64
65 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
66
67 31/xor 3/mod/direct 1/rm32/ECX . . . 1/r32/ECX . .
68
69
70 50/push-EAX
71 ff 6/subop/push 0/mod/indirect 6/rm32/ESI . . . . . .
72
73 e8/call read/disp32
74
75 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
76
77 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0/imm32
78 75/jump-if-not-equal $read-byte:from-stream/disp8
79 b8/copy-to-EAX 0xffffffff/imm32/Eof
80 eb/jump $read-byte:end/disp8
81 $read-byte:from-stream:
82
83
84 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . .
85 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/AL 0x10/disp8 .
86
87 ff 0/subop/increment 1/mod/*+disp8 6/rm32/ESI . . . . 8/disp8 .
88 $read-byte:end:
89
90 5e/pop-to-ESI
91 59/pop-to-ECX
92
93 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
94 5d/pop-to-EBP
95 c3/return
96
97
98
99 test-read-byte-single:
100
101
102
103
104 68/push _test-stream/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 b8/copy-to-EAX _test-buffered-file/imm32
112 05/add-to-EAX 4/imm32
113 50/push-EAX
114
115 e8/call clear-stream/disp32
116
117 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
118
119
120 68/push "Ab"/imm32
121 68/push _test-stream/imm32
122
123 e8/call write/disp32
124
125 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
126
127
128 68/push _test-buffered-file/imm32
129
130 e8/call read-byte/disp32
131
132 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
133
134
135 68/push "F - test-read-byte-single"/imm32
136 68/push 0x41/imm32
137 50/push-EAX
138
139 e8/call check-ints-equal/disp32
140
141 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
142
143 c3/return
144
145 test-read-byte-multiple:
146
147
148
149
150 68/push _test-stream/imm32
151
152 e8/call clear-stream/disp32
153
154 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
155
156
157 b8/copy-to-EAX _test-buffered-file/imm32
158 05/add-to-EAX 4/imm32
159 50/push-EAX
160
161 e8/call clear-stream/disp32
162
163 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
164
165
166 68/push "Ab"/imm32
167 68/push _test-stream/imm32
168
169 e8/call write/disp32
170
171 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
172
173
174 68/push _test-buffered-file/imm32
175
176 e8/call read-byte/disp32
177
178 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
179
180
181 68/push _test-buffered-file/imm32
182
183 e8/call read-byte/disp32
184
185 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
186
187
188 68/push "F - test-read-byte-multiple"/imm32
189 68/push 0x62/imm32
190 50/push-EAX
191
192 e8/call check-ints-equal/disp32
193
194 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
195
196 c3/return
197
198 test-read-byte-end-of-file:
199
200
201
202
203 68/push _test-stream/imm32
204
205 e8/call clear-stream/disp32
206
207 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
208
209
210 b8/copy-to-EAX _test-buffered-file/imm32
211 05/add-to-EAX 4/imm32
212 50/push-EAX
213
214 e8/call clear-stream/disp32
215
216 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
217
218
219 68/push _test-buffered-file/imm32
220
221 e8/call read-byte/disp32
222
223 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
224
225
226 68/push "F - test-read-byte-end-of-file"/imm32
227 68/push 0xffffffff/imm32/Eof
228 50/push-EAX
229
230 e8/call check-ints-equal/disp32
231
232 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
233
234 c3/return
235
236 test-read-byte-refills-buffer:
237
238
239
240
241 68/push _test-stream/imm32
242
243 e8/call clear-stream/disp32
244
245 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
246
247
248 b8/copy-to-EAX _test-buffered-file/imm32
249 05/add-to-EAX 4/imm32
250 50/push-EAX
251
252 e8/call clear-stream/disp32
253
254 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
255
256
257 68/push "Abcdefgh"/imm32
258 68/push _test-stream/imm32
259
260 e8/call write/disp32
261
262 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
263
264
265 b8/copy-to-EAX _test-buffered-file/imm32
266 c7 0/subop/copy 1/mod/*+disp8 0/rm32/EAX . . . . 8/disp8 6/imm32
267
268
269 68/push _test-buffered-file/imm32
270
271 e8/call read-byte/disp32
272
273 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
274
275
276 68/push "F - test-read-byte-refills-buffer"/imm32
277 68/push 0x41/imm32
278 50/push-EAX
279
280 e8/call check-ints-equal/disp32
281
282 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
283
284 c3/return
285
286 == data
287
288
289 _test-buffered-file:
290
291 _test-stream/imm32
292
293 0/imm32
294
295 0/imm32
296
297 6/imm32
298
299 00 00 00 00 00 00
300
301