https://github.com/akkartik/mu/blob/master/071read-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
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 b8/copy-to-eax 1/imm32/exit
108 cd/syscall 0x80/imm8
109
110
111 test-read-line-buffered:
112
113
114
115
116 68/push _test-stream/imm32
117
118 e8/call clear-stream/disp32
119
120 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
121
122
123 68/push $_test-buffered-file->buffer/imm32
124
125 e8/call clear-stream/disp32
126
127 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
128
129
130 68/push _test-tmp-stream/imm32
131
132 e8/call clear-stream/disp32
133
134 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
135
136
137 68/push "ab\ncd"/imm32
138 68/push _test-stream/imm32
139
140 e8/call write/disp32
141
142 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
143
144
145
146 68/push _test-tmp-stream/imm32
147 68/push _test-buffered-file/imm32
148
149 e8/call read-line-buffered/disp32
150
151 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
152
153
154 68/push "F - test-read-line-buffered"/imm32
155 68/push "ab"/imm32
156 68/push _test-tmp-stream/imm32
157
158 e8/call check-next-stream-line-equal/disp32
159
160 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
161
162 c3/return
163
164 test-read-line-buffered-reads-final-line-until-Eof:
165
166
167
168 68/push _test-stream/imm32
169
170 e8/call clear-stream/disp32
171
172 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
173
174
175 68/push $_test-buffered-file->buffer/imm32
176
177 e8/call clear-stream/disp32
178
179 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
180
181
182 68/push _test-tmp-stream/imm32
183
184 e8/call clear-stream/disp32
185
186 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
187
188
189 68/push "cd"/imm32
190 68/push _test-stream/imm32
191
192 e8/call write/disp32
193
194 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
195
196
197
198 68/push _test-tmp-stream/imm32
199 68/push _test-buffered-file/imm32
200
201 e8/call read-line-buffered/disp32
202
203 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
204
205
206 68/push "F - test-read-line-buffered-reads-final-line-until-Eof"/imm32
207 68/push "cd"/imm32
208 68/push _test-tmp-stream/imm32
209
210 e8/call check-stream-equal/disp32
211
212 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
213
214 c3/return
215
216
217
218
219 read-line:
220
221
222
223
224
225
226
227
228
229
230 55/push-ebp
231 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
232
233 50/push-eax
234 51/push-ecx
235 52/push-edx
236 56/push-esi
237 57/push-edi
238
239 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 .
240
241 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 .
242
243 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 .
244
245 8b/copy 0/mod/indirect 7/rm32/edi . . . 2/r32/edx . .
246 $read-line:loop:
247
248 3b/compare 1/mod/*+disp8 7/rm32/edi . . . 2/r32/edx 8/disp8 .
249 0f 8d/jump-if->= $read-line:abort/disp32
250
251 3b/compare 0/mod/indirect 6/rm32/esi . . . 1/r32/ecx . .
252 7d/jump-if->= $read-line:end/disp8
253
254 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . .
255 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/AL 0xc/disp8 .
256
257 88/copy-byte 1/mod/*+disp8 4/rm32/sib 7/base/edi 2/index/edx . 0/r32/AL 0xc/disp8 .
258
259 41/increment-ecx
260
261 42/increment-edx
262
263 3d/compare-eax-and 0xa/imm32
264 0f 85/jump-if-!= $read-line:loop/disp32
265 $read-line:end:
266
267 89/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 .
268
269 89/copy 0/mod/indirect 7/rm32/edi . . . 2/r32/edx . .
270
271 5f/pop-to-edi
272 5e/pop-to-esi
273 5a/pop-to-edx
274 59/pop-to-ecx
275 58/pop-to-eax
276
277 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
278 5d/pop-to-ebp
279 c3/return
280
281 $read-line:abort:
282
283
284 68/push "read-line: line too long\n"/imm32
285 68/push 2/imm32/stderr
286
287 e8/call _write/disp32
288
289 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
290
291 bb/copy-to-ebx 1/imm32
292 b8/copy-to-eax 1/imm32/exit
293 cd/syscall 0x80/imm8
294
295
296 test-read-line:
297
298
299
300
301 68/push _test-stream/imm32
302
303 e8/call clear-stream/disp32
304
305 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
306
307
308 68/push _test-tmp-stream/imm32
309
310 e8/call clear-stream/disp32
311
312 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
313
314
315 68/push "ab\ncd"/imm32
316 68/push _test-stream/imm32
317
318 e8/call write/disp32
319
320 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
321
322
323
324 68/push _test-tmp-stream/imm32
325 68/push _test-stream/imm32
326
327 e8/call read-line/disp32
328
329 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
330
331
332 68/push "F - test-read-line"/imm32
333 68/push "ab"/imm32
334 68/push _test-tmp-stream/imm32
335
336 e8/call check-next-stream-line-equal/disp32
337
338 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
339
340 c3/return
341
342 test-read-line-reads-final-line-until-Eof:
343
344
345
346 68/push _test-stream/imm32
347
348 e8/call clear-stream/disp32
349
350 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
351
352
353 68/push _test-tmp-stream/imm32
354
355 e8/call clear-stream/disp32
356
357 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
358
359
360 68/push "cd"/imm32
361 68/push _test-stream/imm32
362
363 e8/call write/disp32
364
365 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
366
367
368
369 68/push _test-tmp-stream/imm32
370 68/push _test-stream/imm32
371
372 e8/call read-line/disp32
373
374 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
375
376
377 68/push "F - test-read-line-reads-final-line-until-Eof"/imm32
378 68/push "cd"/imm32
379 68/push _test-tmp-stream/imm32
380
381 e8/call check-stream-equal/disp32
382
383 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
384
385 c3/return
386
387