https://github.com/akkartik/mu/blob/main/127next-word.subx
1
2
3 == code
4
5
6
7
8
9
10
11 next-word:
12
13 55/push-ebp
14 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
15
16 50/push-eax
17 51/push-ecx
18 56/push-esi
19 57/push-edi
20
21 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 .
22
23 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 .
24
25
26 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
27
28 e8/call skip-chars-matching-whitespace/disp32
29
30 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
31 $next-word:check0:
32
33
34 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 .
35
36 3b/compare 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . .
37 7c/jump-if-< $next-word:check-for-comment/disp8
38
39 c7 0/subop/copy 0/mod/direct 7/rm32/edi . . . . . 0/imm32
40 c7 0/subop/copy 1/mod/*+disp8 7/rm32/edi . . . . 4/disp8 0/imm32
41 e9/jump $next-word:end/disp32
42 $next-word:check-for-comment:
43
44 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 .
45 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/eax 0xc/disp8 .
46 89/copy 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . .
47
48
49 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . .
50 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/AL 0xc/disp8 .
51
52 3d/compare-eax-and 0x23/imm32/pound
53 0f 85/jump-if-!= $next-word:regular-word/disp32
54 $next-word:comment:
55
56 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/eax 0xc/disp8 .
57 89/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 4/disp8 .
58
59 8b/copy 0/mod/indirect 6/rm32/esi . . . 1/r32/ecx . .
60 $next-word:comment-loop:
61
62 39/compare 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 .
63 0f 8d/jump-if->= $next-word:comment-break/disp32
64
65 ff 0/subop/increment 1/mod/*+disp8 6/rm32/esi . . . . 4/disp8 .
66
67 ff 0/subop/increment 1/mod/*+disp8 7/rm32/edi . . . . 4/disp8 .
68
69 8b/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 4/disp8 .
70 8a/copy-byte 0/mod/indirect 0/rm32/eax . . . 0/r32/AL . .
71 25/and-eax-with 0xff/imm32
72 3d/compare-eax-and 0xa/imm32/newline
73 0f 84/jump-if-= $next-word:comment-break/disp32
74
75 e9/jump $next-word:comment-loop/disp32
76 $next-word:comment-break:
77
78 e9/jump $next-word:end/disp32
79 $next-word:regular-word:
80
81
82 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
83
84 e8/call skip-chars-not-matching-whitespace/disp32
85
86 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
87
88 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 .
89 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/eax 0xc/disp8 .
90 89/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 4/disp8 .
91 $next-word:end:
92
93 5f/pop-to-edi
94 5e/pop-to-esi
95 59/pop-to-ecx
96 58/pop-to-eax
97
98 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
99 5d/pop-to-ebp
100 c3/return
101
102 test-next-word:
103
104 55/push-ebp
105 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
106
107
108
109 68/push _test-stream/imm32
110
111 e8/call clear-stream/disp32
112
113 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
114
115 68/push 0/imm32/end
116 68/push 0/imm32/start
117 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
118
119
120 68/push " ab"/imm32
121 68/push _test-stream/imm32
122
123 e8/call write/disp32
124
125 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
126
127
128 51/push-ecx
129 68/push _test-stream/imm32
130
131 e8/call next-word/disp32
132
133 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
134
135
136
137 68/push "F - test-next-word: start"/imm32
138 68/push 0xe/imm32
139
140 8b/copy 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . .
141 81 5/subop/subtract 3/mod/direct 0/rm32/eax . . . . . _test-stream/imm32
142 50/push-eax
143
144 e8/call check-ints-equal/disp32
145
146 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
147
148
149
150 68/push "F - test-next-word: end"/imm32
151 68/push 0x10/imm32
152
153 8b/copy 1/mod/*+disp8 1/rm32/ecx . . . 0/r32/eax 4/disp8 .
154 81 5/subop/subtract 3/mod/direct 0/rm32/eax . . . . . _test-stream/imm32
155 50/push-eax
156
157 e8/call check-ints-equal/disp32
158
159 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
160
161 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
162 5d/pop-to-ebp
163 c3/return
164
165 test-next-word-returns-whole-comment:
166
167 55/push-ebp
168 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
169
170
171
172 68/push _test-stream/imm32
173
174 e8/call clear-stream/disp32
175
176 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
177
178 68/push 0/imm32/end
179 68/push 0/imm32/start
180 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
181
182
183 68/push " # a"/imm32
184 68/push _test-stream/imm32
185
186 e8/call write/disp32
187
188 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
189
190
191 51/push-ecx
192 68/push _test-stream/imm32
193
194 e8/call next-word/disp32
195
196 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
197
198
199
200 68/push "F - test-next-word-returns-whole-comment: start"/imm32
201 68/push 0xe/imm32
202
203 8b/copy 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . .
204 81 5/subop/subtract 3/mod/direct 0/rm32/eax . . . . . _test-stream/imm32
205 50/push-eax
206
207 e8/call check-ints-equal/disp32
208
209 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
210
211
212
213 68/push "F - test-next-word-returns-whole-comment: end"/imm32
214 68/push 0x11/imm32
215
216 8b/copy 1/mod/*+disp8 1/rm32/ecx . . . 0/r32/eax 4/disp8 .
217 81 5/subop/subtract 3/mod/direct 0/rm32/eax . . . . . _test-stream/imm32
218 50/push-eax
219
220 e8/call check-ints-equal/disp32
221
222 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
223
224 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
225 5d/pop-to-ebp
226 c3/return
227
228 test-next-word-returns-empty-string-on-eof:
229
230 55/push-ebp
231 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
232
233
234
235 68/push _test-stream/imm32
236
237 e8/call clear-stream/disp32
238
239 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
240
241 68/push 0/imm32/end
242 68/push 0/imm32/start
243 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
244
245
246
247 51/push-ecx
248 68/push _test-stream/imm32
249
250 e8/call next-word/disp32
251
252 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
253
254
255 68/push "F - test-next-word-returns-empty-string-on-eof"/imm32
256 68/push 0/imm32
257
258 8b/copy 1/mod/*+disp8 1/rm32/ecx . . . 0/r32/eax 4/disp8 .
259 2b/subtract 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . .
260 50/push-eax
261
262 e8/call check-ints-equal/disp32
263
264 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
265
266 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
267 5d/pop-to-ebp
268 c3/return
269
270 test-next-word-returns-empty-string-on-newline:
271
272 55/push-ebp
273 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
274
275
276
277 68/push _test-stream/imm32
278
279 e8/call clear-stream/disp32
280
281 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
282
283 68/push 0/imm32/end
284 68/push 0/imm32/start
285 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
286
287
288 68/push " \n"/imm32
289 68/push _test-stream/imm32
290
291 e8/call write/disp32
292
293 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
294
295
296 51/push-ecx
297 68/push _test-stream/imm32
298
299 e8/call next-word/disp32
300
301 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
302
303
304 68/push "F - test-next-word-returns-empty-string-on-newline"/imm32
305 68/push 0/imm32
306
307 8b/copy 1/mod/*+disp8 1/rm32/ecx . . . 0/r32/eax 4/disp8 .
308 2b/subtract 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . .
309 50/push-eax
310
311 e8/call check-ints-equal/disp32
312
313 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
314
315 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
316 5d/pop-to-ebp
317 c3/return
318
319
320
321 next-raw-word:
322
323 55/push-ebp
324 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
325
326 50/push-eax
327 51/push-ecx
328 56/push-esi
329 57/push-edi
330
331 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 .
332
333 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 .
334
335
336 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
337
338 e8/call skip-chars-matching-whitespace/disp32
339
340 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
341 $next-raw-word:check0:
342
343
344 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 .
345
346 3b/compare 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . .
347 7c/jump-if-< $next-raw-word:word-exists/disp8
348
349 c7 0/subop/copy 0/mod/direct 7/rm32/edi . . . . . 0/imm32
350 c7 0/subop/copy 1/mod/*+disp8 7/rm32/edi . . . . 4/disp8 0/imm32
351 eb/jump $next-raw-word:end/disp8
352 $next-raw-word:word-exists:
353
354 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 .
355 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/eax 0xc/disp8 .
356 89/copy 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . .
357
358
359 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
360
361 e8/call skip-chars-not-matching-whitespace/disp32
362
363 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
364
365 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 .
366 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/eax 0xc/disp8 .
367 89/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 4/disp8 .
368 $next-raw-word:end:
369
370 5f/pop-to-edi
371 5e/pop-to-esi
372 59/pop-to-ecx
373 58/pop-to-eax
374
375 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
376 5d/pop-to-ebp
377 c3/return