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:
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: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:abort/disp8
48
49 3b/compare 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
50 7c/jump-if-lesser $read-line: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 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0/imm32
73 74/jump-if-equal $read-line:end/disp8
74 $read-line: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 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xa/imm32
86 75/jump-if-not-equal $read-line:loop/disp8
87 $read-line: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:abort:
104
105
106 68/push "read-line: line too long"/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
114 68/push Newline/imm32
115 68/push 2/imm32/stderr
116
117 e8/call _write/disp32
118
119 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
120
121 bb/copy-to-EBX 1/imm32
122 b8/copy-to-EAX 1/imm32/exit
123 cd/syscall 0x80/imm8
124
125
126 test-read-line:
127
128
129
130
131 68/push _test-stream/imm32
132
133 e8/call clear-stream/disp32
134
135 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
136
137
138 b8/copy-to-EAX _test-buffered-file/imm32
139 05/add-to-EAX 4/imm32
140 50/push-EAX
141
142 e8/call clear-stream/disp32
143
144 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
145
146
147 68/push _test-tmp-stream/imm32
148
149 e8/call clear-stream/disp32
150
151 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
152
153
154
155 68/push "ab"/imm32
156 68/push _test-stream/imm32
157
158 e8/call write/disp32
159
160 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
161
162
163 68/push Newline/imm32
164 68/push _test-stream/imm32
165
166 e8/call write/disp32
167
168 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
169
170
171 68/push "cd"/imm32
172 68/push _test-stream/imm32
173
174 e8/call write/disp32
175
176 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
177
178
179
180 68/push _test-tmp-stream/imm32
181 68/push _test-buffered-file/imm32
182
183 e8/call read-line/disp32
184
185 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
186
187
188 68/push "F - test-read-line"/imm32
189 68/push "ab"/imm32
190 68/push _test-tmp-stream/imm32
191
192 e8/call check-next-stream-line-equal/disp32
193
194 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
195
196 c3/return
197
198 test-read-line-reads-final-line-until-Eof:
199
200
201
202 68/push _test-stream/imm32
203
204 e8/call clear-stream/disp32
205
206 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
207
208
209 b8/copy-to-EAX _test-buffered-file/imm32
210 05/add-to-EAX 4/imm32
211 50/push-EAX
212
213 e8/call clear-stream/disp32
214
215 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
216
217
218 68/push _test-tmp-stream/imm32
219
220 e8/call clear-stream/disp32
221
222 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
223
224
225 68/push "cd"/imm32
226 68/push _test-stream/imm32
227
228 e8/call write/disp32
229
230 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
231
232
233
234 68/push _test-tmp-stream/imm32
235 68/push _test-buffered-file/imm32
236
237 e8/call read-line/disp32
238
239 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
240
241
242 68/push "F - test-read-line-reads-final-line-until-Eof"/imm32
243 68/push "cd"/imm32
244 68/push _test-tmp-stream/imm32
245
246 e8/call check-stream-equal/disp32
247
248 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
249
250 c3/return
251
252