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