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