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