https://github.com/akkartik/mu/blob/master/subx/071read-line.subx
1 == code
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 read-line-buffered:
17
18
19
20
21
22
23
24
25
26
27
28 55/push-EBP
29 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
30
31 50/push-EAX
32 51/push-ECX
33 52/push-EDX
34 56/push-ESI
35 57/push-EDI
36
37 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 8/disp8 .
38
39 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 8/disp8 .
40
41 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 0xc/disp8 .
42
43 8b/copy 0/mod/indirect 7/rm32/EDI . . . 2/r32/EDX . .
44 $read-line-buffered:loop:
45
46 3b/compare 1/mod/*+disp8 7/rm32/EDI . . . 2/r32/EDX 8/disp8 .
47 7d/jump-if-greater-or-equal $read-line-buffered:abort/disp8
48
49 3b/compare 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
50 7c/jump-if-lesser $read-line-buffered:from-stream/disp8
51
52
53 8d/copy-address 1/mod/*+disp8 6/rm32/ESI . . . 0/r32/EAX 4/disp8 .
54 50/push-EAX
55
56 e8/call clear-stream/disp32
57
58 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
59
60 31/xor 3/mod/direct 1/rm32/ECX . . . 1/r32/ECX . .
61
62
63 50/push-EAX
64 ff 6/subop/push 0/mod/indirect 6/rm32/ESI . . . . . .
65
66 e8/call read/disp32
67
68 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
69
70
71
72 3d/compare-EAX-and 0/imm32
73 74/jump-if-equal $read-line-buffered:end/disp8
74 $read-line-buffered:from-stream:
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 88/copy-byte 1/mod/*+disp8 4/rm32/sib 7/base/EDI 2/index/EDX . 0/r32/AL 0xc/disp8 .
80
81 41/increment-ECX
82
83 42/increment-EDX
84
85 3d/compare-EAX-and 0xa/imm32
86 75/jump-if-not-equal $read-line-buffered:loop/disp8
87 $read-line-buffered:end:
88
89 89/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 8/disp8 .
90
91 89/copy 0/mod/indirect 7/rm32/EDI . . . 2/r32/EDX . .
92
93 5f/pop-to-EDI
94 5e/pop-to-ESI
95 5a/pop-to-EDX
96 59/pop-to-ECX
97 58/pop-to-EAX
98
99 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
100 5d/pop-to-EBP
101 c3/return
102
103 $read-line-buffered:abort:
104
105
106 68/push "read-line-buffered: line too long\n"/imm32
107 68/push 2/imm32/stderr
108
109 e8/call _write/disp32
110
111 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
112
113 bb/copy-to-EBX 1/imm32
114 b8/copy-to-EAX 1/imm32/exit
115 cd/syscall 0x80/imm8
116
117
118 test-read-line-buffered:
119
120
121
122
123 68/push _test-stream/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 b8/copy-to-EAX _test-buffered-file/imm32
131 05/add-to-EAX 4/imm32
132 50/push-EAX
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 _test-tmp-stream/imm32
140
141 e8/call clear-stream/disp32
142
143 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
144
145
146 68/push "ab\ncd"/imm32
147 68/push _test-stream/imm32
148
149 e8/call write/disp32
150
151 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
152
153
154
155 68/push _test-tmp-stream/imm32
156 68/push _test-buffered-file/imm32
157
158 e8/call read-line-buffered/disp32
159
160 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
161
162
163 68/push "F - test-read-line-buffered"/imm32
164 68/push "ab"/imm32
165 68/push _test-tmp-stream/imm32
166
167 e8/call check-next-stream-line-equal/disp32
168
169 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
170
171 c3/return
172
173 test-read-line-buffered-reads-final-line-until-Eof:
174
175
176
177 68/push _test-stream/imm32
178
179 e8/call clear-stream/disp32
180
181 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
182
183
184 b8/copy-to-EAX _test-buffered-file/imm32
185 05/add-to-EAX 4/imm32
186 50/push-EAX
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 _test-tmp-stream/imm32
194
195 e8/call clear-stream/disp32
196
197 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
198
199
200 68/push "cd"/imm32
201 68/push _test-stream/imm32
202
203 e8/call write/disp32
204
205 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
206
207
208
209 68/push _test-tmp-stream/imm32
210 68/push _test-buffered-file/imm32
211
212 e8/call read-line-buffered/disp32
213
214 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
215
216
217 68/push "F - test-read-line-buffered-reads-final-line-until-Eof"/imm32
218 68/push "cd"/imm32
219 68/push _test-tmp-stream/imm32
220
221 e8/call check-stream-equal/disp32
222
223 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
224
225 c3/return
226
227