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