https://github.com/akkartik/mu/blob/master/subx/069next-token.subx
1 == code
2
3
4
5
6
7 e8/call run-tests/disp32
8
9 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32
10 b8/copy-to-EAX 1/imm32/exit
11 cd/syscall 0x80/imm8
12
13
14
15
16
17 next-token:
18
19 55/push-EBP
20 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
21
22 50/push-EAX
23 51/push-ECX
24 56/push-ESI
25 57/push-EDI
26
27 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 8/disp8 .
28
29 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 0x10/disp8 .
30
31
32 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 .
33 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
34
35 e8/call skip-chars-matching/disp32
36
37 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
38
39 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
40 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/EAX 0xc/disp8 .
41 89/copy 0/mod/indirect 7/rm32/EDI . . . 0/r32/EAX . .
42
43
44 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 .
45 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
46
47 e8/call skip-chars-not-matching/disp32
48
49 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
50
51 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
52 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/EAX 0xc/disp8 .
53 89/copy 1/mod/*+disp8 7/rm32/EDI . . . 0/r32/EAX 4/disp8 .
54
55 5f/pop-to-EDI
56 5e/pop-to-ESI
57 59/pop-to-ECX
58 58/pop-to-EAX
59
60 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
61 5d/pop-to-EBP
62 c3/return
63
64 test-next-token:
65
66 55/push-EBP
67 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
68
69
70
71 68/push _test-stream/imm32
72
73 e8/call clear-stream/disp32
74
75 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
76
77 68/push 0/imm32/end
78 68/push 0/imm32/start
79 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
80
81
82 68/push " ab"/imm32
83 68/push _test-stream/imm32
84
85 e8/call write/disp32
86
87 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
88
89
90 51/push-ECX
91 68/push 0x20/imm32
92 68/push _test-stream/imm32
93
94 e8/call next-token/disp32
95
96 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
97
98
99
100 68/push "F - test-next-token: start"/imm32
101 68/push 0xe/imm32
102
103 8b/copy 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . .
104 81 5/subop/subtract 3/mod/direct 0/rm32/EAX . . . . . _test-stream/imm32
105 50/push-EAX
106
107 e8/call check-ints-equal/disp32
108
109 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
110
111
112
113 68/push "F - test-next-token: end"/imm32
114 68/push 0x10/imm32
115
116 8b/copy 1/mod/*+disp8 1/rm32/ECX . . . 0/r32/EAX 4/disp8 .
117 81 5/subop/subtract 3/mod/direct 0/rm32/EAX . . . . . _test-stream/imm32
118 50/push-EAX
119
120 e8/call check-ints-equal/disp32
121
122 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
123
124 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
125 5d/pop-to-EBP
126 c3/return
127
128 test-next-token-eof:
129
130 55/push-EBP
131 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
132
133
134
135 68/push _test-stream/imm32
136
137 e8/call clear-stream/disp32
138
139 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
140
141 68/push 0/imm32/end
142 68/push 0/imm32/start
143 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
144
145
146
147 51/push-ECX
148 68/push 0x20/imm32
149 68/push _test-stream/imm32
150
151 e8/call next-token/disp32
152
153 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
154
155
156 68/push "F - test-next-token-eof"/imm32
157 ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 .
158 ff 6/subop/push 0/mod/indirect 1/rm32/ECX . . . . . .
159
160 e8/call check-ints-equal/disp32
161
162 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
163
164 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
165 5d/pop-to-EBP
166 c3/return
167
168 skip-chars-matching:
169
170 55/push-EBP
171 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
172
173 50/push-EAX
174 51/push-ECX
175 52/push-EDX
176 56/push-ESI
177
178 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 8/disp8 .
179
180 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
181
182 8b/copy 0/mod/indirect 6/rm32/ESI . . . 3/r32/EBX . .
183
184 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 2/r32/EDX 0xc/disp8 .
185 $skip-chars-matching:loop:
186
187 3b/compare 3/mod/direct 3/rm32/EBX . . . 1/r32/ECX . .
188 7d/jump-if-greater-or-equal $skip-chars-matching:end/disp8
189
190 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . .
191 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/AL 0xc/disp8 .
192
193 39/compare 3/mod/direct 0/rm32/EAX . . . 2/r32/EDX . .
194 75/jump-if-not-equal $skip-chars-matching:end/disp8
195
196 41/inc-ECX
197 eb/jump $skip-chars-matching:loop/disp8
198 $skip-chars-matching:end:
199
200 89/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
201
202 5e/pop-to-ESI
203 5a/pop-to-EDX
204 59/pop-to-ECX
205 58/pop-to-EAX
206
207 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
208 5d/pop-to-EBP
209 c3/return
210
211 test-skip-chars-matching:
212
213
214
215 68/push _test-stream/imm32
216
217 e8/call clear-stream/disp32
218
219 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
220
221
222 68/push " ab"/imm32
223 68/push _test-stream/imm32
224
225 e8/call write/disp32
226
227 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
228
229
230 68/push 0x20/imm32
231 68/push _test-stream/imm32
232
233 e8/call skip-chars-matching/disp32
234
235 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
236
237
238 68/push "F - test-skip-chars-matching"/imm32
239 68/push 2/imm32
240
241 b8/copy-to-EAX _test-stream/imm32
242 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 4/disp8 .
243
244 e8/call check-ints-equal/disp32
245
246 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
247
248 c3/return
249
250 test-skip-chars-matching-none:
251
252
253
254 68/push _test-stream/imm32
255
256 e8/call clear-stream/disp32
257
258 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
259
260
261 68/push "ab"/imm32
262 68/push _test-stream/imm32
263
264 e8/call write/disp32
265
266 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
267
268
269 68/push 0x20/imm32
270 68/push _test-stream/imm32
271
272 e8/call skip-chars-matching/disp32
273
274 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
275
276
277 68/push "F - test-skip-chars-matching-none"/imm32
278 68/push 0/imm32
279
280 b8/copy-to-EAX _test-stream/imm32
281 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 4/disp8 .
282
283 e8/call check-ints-equal/disp32
284
285 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
286
287 c3/return
288
289
290 skip-chars-not-matching:
291
292 55/push-EBP
293 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
294
295 50/push-EAX
296 51/push-ECX
297 52/push-EDX
298 56/push-ESI
299
300 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 8/disp8 .
301
302 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
303
304 8b/copy 0/mod/indirect 6/rm32/ESI . . . 3/r32/EBX . .
305
306 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 2/r32/EDX 0xc/disp8 .
307 $skip-chars-not-matching:loop:
308
309 3b/compare 3/mod/direct 3/rm32/EBX . . . 1/r32/ECX . .
310 7d/jump-if-greater-or-equal $skip-chars-not-matching:end/disp8
311
312 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . .
313 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/AL 0xc/disp8 .
314
315 39/compare 3/mod/direct 0/rm32/EAX . . . 2/r32/EDX . .
316 74/jump-if-equal $skip-chars-not-matching:end/disp8
317
318 41/inc-ECX
319 eb/jump $skip-chars-not-matching:loop/disp8
320 $skip-chars-not-matching:end:
321
322 89/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 .
323
324 5e/pop-to-ESI
325 5a/pop-to-EDX
326 59/pop-to-ECX
327 58/pop-to-EAX
328
329 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
330 5d/pop-to-EBP
331 c3/return
332
333 test-skip-chars-not-matching:
334
335
336
337 68/push _test-stream/imm32
338
339 e8/call clear-stream/disp32
340
341 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
342
343
344 68/push "ab "/imm32
345 68/push _test-stream/imm32
346
347 e8/call write/disp32
348
349 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
350
351
352 68/push 0x20/imm32
353 68/push _test-stream/imm32
354
355 e8/call skip-chars-not-matching/disp32
356
357 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
358
359
360 68/push "F - test-skip-chars-not-matching"/imm32
361 68/push 2/imm32
362
363 b8/copy-to-EAX _test-stream/imm32
364 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 4/disp8 .
365
366 e8/call check-ints-equal/disp32
367
368 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
369
370 c3/return
371
372 test-skip-chars-not-matching-none:
373
374
375
376 68/push _test-stream/imm32
377
378 e8/call clear-stream/disp32
379
380 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
381
382
383 68/push " ab"/imm32
384 68/push _test-stream/imm32
385
386 e8/call write/disp32
387
388 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
389
390
391 68/push 0x20/imm32
392 68/push _test-stream/imm32
393
394 e8/call skip-chars-not-matching/disp32
395
396 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
397
398
399 68/push "F - test-skip-chars-not-matching-none"/imm32
400 68/push 0/imm32
401
402 b8/copy-to-EAX _test-stream/imm32
403 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 4/disp8 .
404
405 e8/call check-ints-equal/disp32
406
407 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
408
409 c3/return
410
411 test-skip-chars-not-matching-all:
412
413
414
415 68/push _test-stream/imm32
416
417 e8/call clear-stream/disp32
418
419 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
420
421
422 68/push "ab"/imm32
423 68/push _test-stream/imm32
424
425 e8/call write/disp32
426
427 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
428
429
430 68/push 0x20/imm32
431 68/push _test-stream/imm32
432
433 e8/call skip-chars-not-matching/disp32
434
435 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
436
437
438 68/push "F - test-skip-chars-not-matching-all"/imm32
439 68/push 2/imm32
440
441 b8/copy-to-EAX _test-stream/imm32
442 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 4/disp8 .
443
444 e8/call check-ints-equal/disp32
445
446 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
447
448 c3/return
449
450