about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--069allocate.subx2
-rwxr-xr-xapps/assortbin44102 -> 44102 bytes
-rwxr-xr-xapps/crenshaw2-1bin43453 -> 43453 bytes
-rwxr-xr-xapps/crenshaw2-1bbin44000 -> 44000 bytes
-rwxr-xr-xapps/dquotesbin47724 -> 47724 bytes
-rwxr-xr-xapps/factorialbin42546 -> 42546 bytes
-rwxr-xr-xapps/hexbin46292 -> 46292 bytes
-rwxr-xr-xapps/packbin56437 -> 56437 bytes
-rwxr-xr-xapps/surveybin54048 -> 54048 bytes
-rwxr-xr-xapps/testsbin42874 -> 42874 bytes
10 files changed, 1 insertions, 1 deletions
diff --git a/069allocate.subx b/069allocate.subx
index 65a7f166..587e4bf7 100644
--- a/069allocate.subx
+++ b/069allocate.subx
@@ -33,7 +33,7 @@ Heap-size:  # int
   0x400000/imm32/4MB
 
 Next-alloc-id:  # int
-  1/imm32
+  0x80000000/imm32
 
 == code
 #   instruction                     effective address                                                   register    displacement    immediate
diff --git a/apps/assort b/apps/assort
index d1b23ee7..0f20ee49 100755
--- a/apps/assort
+++ b/apps/assort
Binary files differdiff --git a/apps/crenshaw2-1 b/apps/crenshaw2-1
index eace889e..555e1b27 100755
--- a/apps/crenshaw2-1
+++ b/apps/crenshaw2-1
Binary files differdiff --git a/apps/crenshaw2-1b b/apps/crenshaw2-1b
index 776c2377..a173aeec 100755
--- a/apps/crenshaw2-1b
+++ b/apps/crenshaw2-1b
Binary files differdiff --git a/apps/dquotes b/apps/dquotes
index 304882f0..aa4ab28f 100755
--- a/apps/dquotes
+++ b/apps/dquotes
Binary files differdiff --git a/apps/factorial b/apps/factorial
index 5aedf192..c9d75a9f 100755
--- a/apps/factorial
+++ b/apps/factorial
Binary files differdiff --git a/apps/hex b/apps/hex
index e978d40d..f38e0ebb 100755
--- a/apps/hex
+++ b/apps/hex
Binary files differdiff --git a/apps/pack b/apps/pack
index 78e274e9..66313b30 100755
--- a/apps/pack
+++ b/apps/pack
Binary files differdiff --git a/apps/survey b/apps/survey
index c55f6ec0..5855e4f0 100755
--- a/apps/survey
+++ b/apps/survey
Binary files differdiff --git a/apps/tests b/apps/tests
index e4194113..e28be899 100755
--- a/apps/tests
+++ b/apps/tests
Binary files differ
k.com> 2020-01-03 01:36:34 -0800 5876 - address -> addr' href='/akkartik/mu/commit/081table.subx?h=main&id=7e7a8a6eaeb4c22acb94aaca87a7b15c180ca077'>7e7a8a6e ^
33352536 ^
7e7a8a6e ^
33352536 ^

94d68ac2 ^

33352536 ^
94d68ac2 ^

33352536 ^
94d68ac2 ^
33352536 ^

94d68ac2 ^


33352536 ^
2a2a5b1e ^

94d68ac2 ^
33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^



33352536 ^


7a583220 ^
33352536 ^

94d68ac2 ^


15a84e24 ^

33352536 ^
15a84e24 ^



33352536 ^
94d68ac2 ^

15a84e24 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^

33352536 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^

a9d473e2 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^
33352536 ^

94d68ac2 ^



7a583220 ^
33352536 ^

94d68ac2 ^
f1eade72 ^
33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^
33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^


33352536 ^


94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^
33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^


33352536 ^


94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^
7a583220 ^
33352536 ^

94d68ac2 ^


7e7a8a6e ^
94d68ac2 ^








7a583220 ^
33352536 ^

94d68ac2 ^
33352536 ^




7e7a8a6e ^
33352536 ^
7e7a8a6e ^
33352536 ^

94d68ac2 ^

33352536 ^
94d68ac2 ^

33352536 ^
94d68ac2 ^
33352536 ^

94d68ac2 ^


33352536 ^
2a2a5b1e ^

94d68ac2 ^
33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^



33352536 ^


7a583220 ^
33352536 ^

94d68ac2 ^


15a84e24 ^

33352536 ^
15a84e24 ^



33352536 ^
94d68ac2 ^

64d51af4 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^

33352536 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^





33352536 ^
94d68ac2 ^

a9d473e2 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^
33352536 ^

94d68ac2 ^



7a583220 ^
33352536 ^

94d68ac2 ^
f1eade72 ^
33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^
33352536 ^




f1eade72 ^
33352536 ^



94d68ac2 ^

33352536 ^

94d68ac2 ^


33352536 ^


94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^
33352536 ^




f1eade72 ^
33352536 ^



94d68ac2 ^

33352536 ^

94d68ac2 ^


33352536 ^


94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^
7a583220 ^
33352536 ^

94d68ac2 ^






7e7a8a6e ^
94d68ac2 ^













7a583220 ^
33352536 ^

94d68ac2 ^
33352536 ^




7e7a8a6e ^
33352536 ^
7e7a8a6e ^
33352536 ^

94d68ac2 ^

33352536 ^
94d68ac2 ^

33352536 ^
94d68ac2 ^
33352536 ^

94d68ac2 ^


33352536 ^
2a2a5b1e ^

94d68ac2 ^
33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^


33352536 ^

94d68ac2 ^
33352536 ^

94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^
33352536 ^



94d68ac2 ^
33352536 ^



94d68ac2 ^
33352536 ^



94d68ac2 ^

33352536 ^


7a583220 ^
33352536 ^

94d68ac2 ^









33352536 ^
94d68ac2 ^
33352536 ^

94d68ac2 ^



7a583220 ^
33352536 ^

f1eade72 ^
33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^

33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^


33352536 ^


94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^




33352536 ^
94d68ac2 ^


33352536 ^
8d543783 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^
8d543783 ^
94d68ac2 ^
33352536 ^
94d68ac2 ^

33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^


33352536 ^


94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^




33352536 ^
94d68ac2 ^


33352536 ^
8d543783 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^
8d543783 ^
94d68ac2 ^
33352536 ^
94d68ac2 ^

33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^
33352536 ^

94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^


33352536 ^
8d543783 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^
8d543783 ^
94d68ac2 ^
33352536 ^
94d68ac2 ^
7a583220 ^
33352536 ^

94d68ac2 ^





7e7a8a6e ^
94d68ac2 ^













7a583220 ^
33352536 ^

94d68ac2 ^
33352536 ^




7e7a8a6e ^
33352536 ^
7e7a8a6e ^
33352536 ^

94d68ac2 ^

33352536 ^
94d68ac2 ^

33352536 ^
94d68ac2 ^
33352536 ^

94d68ac2 ^


33352536 ^
2a2a5b1e ^

94d68ac2 ^
33352536 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^


33352536 ^

94d68ac2 ^
33352536 ^

94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^
33352536 ^
94d68ac2 ^
33352536 ^
94d68ac2 ^



33352536 ^


94d68ac2 ^
33352536 ^



94d68ac2 ^
33352536 ^



94d68ac2 ^

33352536 ^


7a583220 ^
33352536 ^

94d68ac2 ^









33352536 ^
94d68ac2 ^
33352536 ^

94d68ac2 ^



7a583220 ^
33352536 ^

f1eade72 ^
33352536 ^
94d68ac2 ^


33352536 ^





f1eade72 ^
33352536 ^


94d68ac2 ^

33352536 ^
94d68ac2 ^

33352536 ^

94d68ac2 ^


33352536 ^


94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^




33352536 ^
94d68ac2 ^


33352536 ^
8d543783 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^
8d543783 ^
94d68ac2 ^
33352536 ^
94d68ac2 ^

33352536 ^
94d68ac2 ^

33352536 ^

94d68ac2 ^


33352536 ^


94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^




33352536 ^
94d68ac2 ^


33352536 ^
8d543783 ^
94d68ac2 ^


33352536 ^
94d68ac2 ^
8d543783 ^
94d68ac2 ^
33352536 ^
94d68ac2 ^

33352536 ^




f1eade72 ^
33352536 ^



94d68ac2 ^

33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^
33352536 ^

94d68ac2 ^


33352536 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^



33352536 ^
94d68ac2 ^


33352536 ^
8d543783 ^

94d68ac2 ^


33352536 ^
94d68ac2 ^
8d543783 ^
94d68ac2 ^
33352536 ^
94d68ac2 ^
7a583220 ^
33352536 ^

94d68ac2 ^

328a8e11 ^
7e7a8a6e ^


0059698b ^









7a583220 ^
33352536 ^

0059698b ^
33352536 ^




7e7a8a6e ^
33352536 ^
7e7a8a6e ^
33352536 ^

0059698b ^

33352536 ^
0059698b ^

33352536 ^
0059698b ^
33352536 ^

0059698b ^


33352536 ^
2a2a5b1e ^

0059698b ^
33352536 ^
0059698b ^


33352536 ^
0059698b ^



33352536 ^


7a583220 ^
33352536 ^

0059698b ^




33352536 ^

0059698b ^


33352536 ^
0059698b ^

328a8e11 ^
33352536 ^
0059698b ^


33352536 ^
0059698b ^

33352536 ^

0059698b ^


33352536 ^
0059698b ^

a9d473e2 ^
33352536 ^
0059698b ^


33352536 ^
0059698b ^

328a8e11 ^
33352536 ^
0059698b ^




33352536 ^
0059698b ^
33352536 ^
0059698b ^


33352536 ^
7a583220 ^
33352536 ^

328a8e11 ^
0059698b ^





33352536 ^
686a52bd ^
0059698b ^
686a52bd ^
0059698b ^


33352536 ^
f1eade72 ^
33352536 ^
0059698b ^


33352536 ^
f1eade72 ^
0059698b ^

33352536 ^
0059698b ^



33352536 ^
0059698b ^


33352536 ^
0059698b ^



33352536 ^
0059698b ^


33352536 ^
0059698b ^
33352536 ^
0059698b ^
33352536 ^
0059698b ^
306812cc ^
0059698b ^

33352536 ^
0059698b ^


33352536 ^
328a8e11 ^
33352536 ^

0059698b ^


33352536 ^

0059698b ^

328a8e11 ^
33352536 ^
328a8e11 ^
33352536 ^
328a8e11 ^
33352536 ^
328a8e11 ^
306812cc ^
328a8e11 ^

33352536 ^
328a8e11 ^

33352536 ^
328a8e11 ^
33352536 ^


328a8e11 ^






33352536 ^
328a8e11 ^

0059698b ^
33352536 ^
0059698b ^
7a583220 ^
33352536 ^


0059698b ^

306812cc ^
7e7a8a6e ^


306812cc ^









7a583220 ^
33352536 ^

306812cc ^
33352536 ^




7e7a8a6e ^
33352536 ^
7e7a8a6e ^
33352536 ^

306812cc ^

33352536 ^
306812cc ^

33352536 ^
306812cc ^
33352536 ^

306812cc ^


33352536 ^
2a2a5b1e ^

306812cc ^
33352536 ^
306812cc ^


33352536 ^
306812cc ^



33352536 ^


7a583220 ^
33352536 ^

306812cc ^




33352536 ^

306812cc ^


33352536 ^
306812cc ^


33352536 ^
306812cc ^


33352536 ^
306812cc ^

33352536 ^

306812cc ^


33352536 ^
306812cc ^

a9d473e2 ^
33352536 ^
306812cc ^


33352536 ^
306812cc ^


33352536 ^
306812cc ^




33352536 ^
306812cc ^
33352536 ^
306812cc ^


33352536 ^
7a583220 ^
33352536 ^

306812cc ^






33352536 ^
686a52bd ^
306812cc ^
686a52bd ^
306812cc ^


33352536 ^
f1eade72 ^
33352536 ^
306812cc ^


33352536 ^
f1eade72 ^
306812cc ^

33352536 ^
f1eade72 ^
33352536 ^








306812cc ^



33352536 ^
306812cc ^


33352536 ^
306812cc ^



33352536 ^
306812cc ^


33352536 ^
306812cc ^
33352536 ^
306812cc ^
33352536 ^
306812cc ^


33352536 ^

306812cc ^

33352536 ^
306812cc ^
33352536 ^



306812cc ^
33352536 ^

306812cc ^


33352536 ^

306812cc ^


33352536 ^
306812cc ^

33352536 ^









306812cc ^


33352536 ^

306812cc ^

33352536 ^
306812cc ^
33352536 ^



306812cc ^






33352536 ^
306812cc ^


33352536 ^
306812cc ^
7a583220 ^
33352536 ^


306812cc ^

2b48729f ^
7e7a8a6e ^
2b48729f ^








7a583220 ^
33352536 ^

2b48729f ^
33352536 ^




7e7a8a6e ^
33352536 ^
7e7a8a6e ^
33352536 ^

2b48729f ^

33352536 ^
2b48729f ^

33352536 ^
2b48729f ^
33352536 ^

2b48729f ^


33352536 ^
2a2a5b1e ^

2b48729f ^
33352536 ^
2b48729f ^


33352536 ^
2b48729f ^


33352536 ^
2b48729f ^

33352536 ^


7a583220 ^
33352536 ^

2b48729f ^


7a583220 ^
33352536 ^

2b48729f ^
f1eade72 ^
33352536 ^
2b48729f ^


33352536 ^

2b48729f ^


33352536 ^
2b48729f ^


33352536 ^
2b48729f ^

33352536 ^
2b48729f ^


33352536 ^
2b48729f ^


33352536 ^


2b48729f ^


33352536 ^

2b48729f ^


33352536 ^
2b48729f ^




33352536 ^
2b48729f ^


33352536 ^
8d543783 ^
2b48729f ^


33352536 ^
2b48729f ^
8d543783 ^
2b48729f ^
33352536 ^
2b48729f ^

33352536 ^
2b48729f ^


33352536 ^
2b48729f ^


33352536 ^

2b48729f ^


33352536 ^
2b48729f ^


33352536 ^
2b48729f ^
7a583220 ^
33352536 ^

2b48729f ^

d826a2d6 ^
7e7a8a6e ^
d826a2d6 ^








7a583220 ^
33352536 ^

d826a2d6 ^
33352536 ^




7e7a8a6e ^
33352536 ^
7e7a8a6e ^
33352536 ^

d826a2d6 ^

33352536 ^
d826a2d6 ^

33352536 ^
d826a2d6 ^
33352536 ^

d826a2d6 ^


33352536 ^
2a2a5b1e ^

d826a2d6 ^
33352536 ^
d826a2d6 ^


33352536 ^
d826a2d6 ^


33352536 ^
d826a2d6 ^

33352536 ^


7a583220 ^
33352536 ^

d826a2d6 ^


7a583220 ^
33352536 ^

d826a2d6 ^
f1eade72 ^
33352536 ^
d826a2d6 ^


33352536 ^
d826a2d6 ^



33352536 ^
d826a2d6 ^


33352536 ^
d826a2d6 ^

33352536 ^




f1eade72 ^
33352536 ^



d826a2d6 ^

33352536 ^

d826a2d6 ^


33352536 ^


d826a2d6 ^


33352536 ^

d826a2d6 ^


33352536 ^
d826a2d6 ^




33352536 ^
d826a2d6 ^


33352536 ^
8d543783 ^
d826a2d6 ^


33352536 ^
d826a2d6 ^
8d543783 ^
d826a2d6 ^
33352536 ^
d826a2d6 ^

33352536 ^




f1eade72 ^
33352536 ^



d826a2d6 ^

33352536 ^

d826a2d6 ^


33352536 ^

d826a2d6 ^


33352536 ^
d826a2d6 ^


33352536 ^
d826a2d6 ^
7a583220 ^
33352536 ^

d826a2d6 ^

94d68ac2 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
                                           
 
                                                                          
                                     



                                                                         
                                                                                       





                                                                                
                                                                       
                                                                     
                                    






                                                                                                                                                 

                                                                                                                                           








                                        
                

                                                                                                                                                                       
                      




                                                                                                                                                                            
                                                    
                                                                                                                                                                          
                                                            

                                                                                                                                                                           

                            
                                                                                                                                                                            

                                                          
                                       
                   

                                                                                                                                                                      


                                 
                                                                                                                                                                  

                                             
                                         
                                                                                                                                                                         


                           
                                                                                                                                                                            



                                   


                 
                

                                                                                                                                                                       


             

                                              
                                                                                                                                                                      



                           
                                                                                                                                                                  

                               
                                           



                           
                                                                                                                                                                  

                             
                                                                                                                                                                      



                           
                                                                                                                                                                  

                              
                          



                           
                                                                                                                                                                  
                        

                                



                         
                

                                                                                                                                                                       
                                                   
                                                                          
                                                                                                                                                                         


                              
                                                                                                                                                                       



                                            
               


                                 
                                                                                                                                                                  



                                            
               


                                 
                                                                                                                                                                  
                 
                                               


                             
               


                       


                                                                                                                                                                  


                                   

                                                                                                                                                                             


                                    
                                                                                                                                                                  
                 
                                               


                             
               


                       


                                                                                                                                                                  


                                   

                                                                                                                                                                             


                                    
                                                                                                                                                                  
              
                

                                                                                                                                                                       


                           
                                                                                                                                                   








                                        
                

                                                                                                                                                                       
                      




                                                                                                                                                                            
                                                    
                                                                                                                                                                          
                                                            

                                                                                                                                                                           

                            
                                                                                                                                                                            

                                                                
                                      
                   

                                                                                                                                                                      


                                
                                                                                                                                                                  

                                             
                                               
                                                                                                                                                                         


                                 
                                                                                                                                                                            



                                         


                 
                

                                                                                                                                                                       


                 

                                              
                                                                                                                                                                      



                           
                                                                                                                                                                  

                               
                                                 



                           
                                                                                                                                                                  

                                         
                                                                                                                                                                      



                                        
                                                                                                                                                                  





                         
                                                                                                                                                                  

                              
                          



                           
                                                                                                                                                                  
                        

                                



                         
                

                                                                                                                                                                       
                                                   
                                                                          
                                                                                                                                                                         


                              
                                                                                                                                                                       



                                            
               


                                 
                                                                                                                                                                  



                                            
               


                                 
                                                                                                                                                                  
                       




                                                                                                                                                                             
                                        



                                                                                                                                                                       

                             

               


                             


                                                                                                                                                                  


                                         

                                                                                                                                                                             


                                    
                                                                                                                                                                  
                       




                                                                                                                                                                             
                                        



                                                                                                                                                                       

                             

               


                             


                                                                                                                                                                  


                                         

                                                                                                                                                                             


                                    
                                                                                                                                                                  
                    
                

                                                                                                                                                                       






                                                                  
                                                                                                           













                                        
                

                                                                                                                                                                       
                      




                                                                                                                                                                            
                                                    
                                                                                                                                                                          
                                                                  

                                                                                                                                                                           

                            
                                                                                                                                                                            

                                                                        
                                       
                   

                                                                                                                                                                      


                                 
                                                                                                                                                                  

                                             
                                                   
                                                                                                                                                                         


                                     
                                                                                                                                                                            


                                             

                                                                                                                                                                 
                                              

                                                                                                                                                                                 


                                                                    

                                                                                                                                                                      


                            
                                                                                                                                                                  
                



                                                                                                                                                                             
                              



                                                                                                                                                                             
                  



                                                                                                                                                                       

                         


                 
                

                                                                                                                                                                       









                                                   
                                                                                                                                                                  
                        

                                



                         
                

                                                                                                                                                                       
                                                                          
                                                                                                                                                                         


                              
                                                                                                                                                                       

                                                                              
                                                         


                             
               


                                 


                                                                                                                                                                  


                                             

                                                                                                                                                                             


                                    
                                                                                                                                                                  




                                                       
                                                                                                                                                                 


                                    
                                                                                                                                                                  
                                                    


                                             
                                                                                                                                                                      
              
                                       
                      
                                                                                                                                                                  

                                                            
                                                         


                             
               


                                 


                                                                                                                                                                  


                                             

                                                                                                                                                                             


                                    
                                                                                                                                                                  




                                                         
                                                                                                                                                                 


                                    
                                                                                                                                                                  
                                                    


                                             
                                                                                                                                                                      
              
                                       
                      
                                                                                                                                                                  

                                                     
                                                         


                             
               


                                 
                                                                                                                                                                  
                          

                                                                                      


                                             

                                                                                                                                                                             


                                    
                                                                                                                                                                  



                                                      
                                                                                                                                                                 


                                    
                                                                                                                                                                  

                                                      


                                             
                                                                                                                                                                      
              
                                       
                      
                                                                                                                                                                  
                        
                

                                                                                                                                                                       





                                                          
                                                                                                                         













                                         
                

                                                                                                                                                                       
                      




                                                                                                                                                                            
                                                    
                                                                                                                                                                          
                                                                  

                                                                                                                                                                           

                                       
                                                                                                                                                                            

                                                                                    
                                      
                   

                                                                                                                                                                      


                                
                                                                                                                                                                  

                                             
                                                               
                                                                                                                                                                         


                                                 
                                                                                                                                                                            


                                                         

                                                                                                                                                                 
                                              

                                                                                                                                                                                 


                                                                       

                                                                                                                                                                      


                            
                                                                                                                                                                  
                                       
                                        
                   
                                                                                                                                                                      



                                   


                                                                                                                                                                        
                              



                                                                                                                                                                             
                  



                                                                                                                                                                       

                               


                 
                

                                                                                                                                                                       









                                                               
                                                                                                                                                                  
                        

                                



                               
                

                                                                                                                                                                       
                                                                          
                                                                                                                                                                         


                              





                                                                                                                                                                             
                                        


                                                                                                                                                                       

                                                                              
                                                                           

                             

               


                                             


                                                                                                                                                                  


                                                         

                                                                                                                                                                             


                                    
                                                                                                                                                                  




                                                         
                                                                                                                                                                 


                                    
                                                                                                                                                                  
                                                    


                                                         
                                                                                                                                                                      
              
                                       
                      
                                                                                                                                                                  

                                                            
                                                                           

                             

               


                                             


                                                                                                                                                                  


                                                         

                                                                                                                                                                             


                                    
                                                                                                                                                                  




                                                         
                                                                                                                                                                 


                                    
                                                                                                                                                                  
                                                    


                                                         
                                                                                                                                                                      
              
                                       
                      
                                                                                                                                                                  

                                                     




                                                                                                                                                                             
                                        



                                                                                                                                                                       

                             

               


                                             
                                                                                                                                                                  
                          

                                                                                      


                                                         

                                                                                                                                                                             


                                    
                                                                                                                                                                  



                                                         
                                                                                                                                                                 


                                    
                                                                                                                                                                  

                                                      


                                                         
                                                                                                                                                                      
              
                                       
                      
                                                                                                                                                                  
                                    
                

                                                                                                                                                                       

             
                              


                                                                                                                 









                                        
                

                                                                                                                                                                       
                      




                                                                                                                                                                            
                                                    
                                                                                                                                                                          
                                                            

                                                                                                                                                                           

                               
                                                                                                                                                                            

                                                                 
                                       
                   

                                                                                                                                                                      


                                 
                                                                                                                                                                  

                                             
                                                 
                                                                                                                                                                         


                                   
                                                                                                                                                                            



                                           


                 
                

                                                                                                                                                                       




                                                 

                                                                                                                                                                      


                                  
                                                                                                                                                                  

                                  
                                                   
                                                                                                                                                                      


                                  
                                                                                                                                                                  

                                

                                                                                                                                                                      


                                  
                                                                                                                                                                  

                                 
                          
                                                                                                                                                                      


                                  
                                                                                                                                                                  

                   
                    
                                                                                                                                                                      




                        
                                                                                                                                                                  
                      
                                


                         
                                                                              
                

                                                                                                                                                                       
           





                                        
                                                                                                                                                                  
                                                        
                   
                                                     


                                
                                                                                                                                                                  
                                                                          
                                                                                                                                                                         


                              
                                                                                                                                                                       
                                  

                    
                                                                                                                                                                       



                                                      
               


                                          
                                                                                                                                                                  



                                            
               


                                 
                                                                                                                                                                  
                          
                                                                                      
                   
                  
                                            
                                     

                             
               


                               
                                                                                                                                                                  
                                    

                                                 


                                           

                                                                                                                                                                             

                                    
                      
                                                                                                                                                                  
                          
                                                                                      
                   
                  
                                            
                                     

                             
               

                               
                                                         
                                           


                                                                                                                                                                  






                                                  
                                                                                                                                                                     

                                    
                      
                                                                                                                                                                  
                      
                


                                                                                                                                                                  

             
                              


                                                                                                                   









                                        
                

                                                                                                                                                                       
                      




                                                                                                                                                                            
                                                    
                                                                                                                                                                          
                                                            

                                                                                                                                                                           

                               
                                                                                                                                                                            

                                                                       
                                      
                   

                                                                                                                                                                      


                                
                                                                                                                                                                  

                                             
                                                       
                                                                                                                                                                         


                                         
                                                                                                                                                                            



                                                 


                 
                

                                                                                                                                                                       




                                                 

                                                                                                                                                                      


                                  
                                                                                                                                                                  


                                                         
                                                                                                                                                                      


                                  
                                                                                                                                                                  

                                      

                                                                                                                                                                      


                                        
                                                                                                                                                                  

                                 
                          
                                                                                                                                                                      


                                  
                                                                                                                                                                  


                    
                                                                                                                                                                      




                            
                                                                                                                                                                  
                      
                                


                         
                                                                              
                

                                                                                                                                                                       






                                        
                                                                                                                                                                  
                                                        
                   
                                                     


                                
                                                                                                                                                                  
                                                                          
                                                                                                                                                                         


                              
                                                                                                                                                                       
                                  

                    
                                                                                                                                                                       
                                    








                                                                                                                                                                             



                                                                                 
               


                                          
                                                                                                                                                                  



                                            
               


                                 
                                                                                                                                                                  
                                
                                                                                           
                   
                  


                                            

                     

                                     
                                                         
                                           



                                                                                                                                                                  
                                          

                                                                                    


                                                 

                                                                                                                                                                             


                                    
                                                                                                                                                                  

                                









                                                                                                                                                                            


                                            

                     

                                     
                                                         
                                           



                                                                                                                                                                  






                                                  
                                                                                                                                                                     


                                    
                                                                                                                                                                  
                            
                


                                                                                                                                                                  

             
                                     
                                                                                                       








                                        
                

                                                                                                                                                                       
                      




                                                                                                                                                                            
                                                    
                                                                                                                                                                          
                                                            

                                                                                                                                                                           

                                  
                                                                                                                                                                            

                                                               
                                       
                   

                                                                                                                                                                      


                                 
                                                                                                                                                                  

                                             
                                               
                                                                                                                                                                         


                                 
                                                                                                                                                                            


                                         
                           

                         


                 
                

                                                                                                                                                                       


               
                

                                                                                                                                                                       
                                          
                                                                           
                                                                                                                                                                         


                              

                                                                                                                                                                       


                             
               


                                 
                                                                                                                                                                  

                                                         
                                                     


                             
               


                             


                                                                                                                                                                  


                                         

                                                                                                                                                                             


                                    
                                                                                                                                                                  




                                                         
                                                                                                                                                                 


                                    
                                                                                                                                                                  
                                                    


                                         
                                                                                                                                                                      
              
                                       
                      
                                                                                                                                                                  

                            
                                                     


                             
               


                             

                                                                                                                                                                  


                                         
               


                                    
                                                                                                                                                                  
                    
                

                                                                                                                                                                       

             
                                     
                                                                                                               








                                        
                

                                                                                                                                                                       
                      




                                                                                                                                                                            
                                                    
                                                                                                                                                                          
                                                            

                                                                                                                                                                           

                                  
                                                                                                                                                                            

                                                                     
                                      
                   

                                                                                                                                                                      


                                
                                                                                                                                                                  

                                             
                                                     
                                                                                                                                                                         


                                       
                                                                                                                                                                            


                                               
                           

                         


                 
                

                                                                                                                                                                       


                     
                

                                                                                                                                                                       
                                          
                                                                           
                                                                                                                                                                         


                              
                                                                                                                                                                       



                                            
               


                                 
                                                                                                                                                                  

                                                         




                                                                                                                                                                             
                                        



                                                                                                                                                                       

                             

               


                                   


                                                                                                                                                                  


                                               

                                                                                                                                                                             


                                    
                                                                                                                                                                  




                                                         
                                                                                                                                                                 


                                    
                                                                                                                                                                  
                                                    


                                               
                                                                                                                                                                      
              
                                       
                      
                                                                                                                                                                  

                              




                                                                                                                                                                             
                                        



                                                                                                                                                                       

                             

               


                                   

                                                                                                                                                                  


                                               
               


                                    
                                                                                                                                                                  
                          
                

                                                                                                                                                                       

             
                            
# A table is a stream of (key, value) rows.
#
# Each row consists of a 4-byte key -- a 'string_key' which is (addr array
# byte) -- and a variable-size value.
#
# Accessing the table performs a linear scan for a key string, and always
# requires passing in the row size.
#
# Table primitives have the form <variant>(stream, <arg>, row-size, ...) -> address/eax
#
# The following table shows available options for <variant>:
#   if not found:           | arg=string              arg=slice
#   ------------------------+---------------------------------------------------
#   abort                   | get                     get-slice
#   insert key              | get-or-insert           leaky-get-or-insert-slice
#   stop                    | get-or-stop             get-slice-or-stop
#   return null             | maybe-get               maybe-get-slice
# Some variants may take extra args.

== code
#   instruction                     effective address                                                   register    displacement    immediate
# . op          subop               mod             rm32          base        index         scale       r32
# . 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes

# if no row is found, abort
# type string_key = (addr array byte)
get:  # table : (addr stream {string_key, T}), key : string_key, row-size : int, abort-message-prefix : (addr array byte) -> eax : (addr T)
    # pseudocode:
    #   curr = table->data
    #   max = &table->data[table->write]
    #   while curr < max
    #     if string-equal?(key, *curr)
    #       return curr+4
    #     curr += row-size
    #   abort
    #
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # . save registers
    51/push-ecx
    52/push-edx
    56/push-esi
    # esi = table
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
    # var curr/ecx : (addr string_key) = table->data
    8d/copy-address                 1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   0xc/disp8       .                 # copy esi+12 to ecx
    # var max/edx : (addr byte) = &table->data[table->write]
    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           2/r32/edx   .               .                 # copy *esi to edx
    8d/copy-address                 0/mod/indirect  4/rm32/sib    1/base/ecx  2/index/edx   .           2/r32/edx   .               .                 # copy ecx+edx to edx
$get:search-loop:
    # if (curr >= max) abort
    39/compare                      3/mod/direct    1/rm32/ecx    .           .             .           2/r32/edx   .               .                 # compare ecx with edx
    73/jump-if-greater-or-equal-unsigned  $get:abort/disp8
    # if (string-equal?(key, *curr)) return curr+4
    # . eax = string-equal?(key, *curr)
    # . . push args
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    # . . call
    e8/call  string-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . if (eax != false) return eax = curr+4
    3d/compare-eax-and  0/imm32/false
    74/jump-if-equal  $get:mismatch/disp8
    8d/copy-address                 1/mod/*+disp8   1/rm32/ecx    .           .             .           0/r32/eax   4/disp8         .                 # copy ecx+4 to eax
    eb/jump  $get:end/disp8
$get:mismatch:
    # curr += row-size
    03/add                          1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # add *(ebp+16) to ecx
    # loop
    eb/jump  $get:search-loop/disp8
$get:end:
    # . restore registers
    5e/pop-to-esi
    5a/pop-to-edx
    59/pop-to-ecx
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

$get:abort:
    # . _write(2/stderr, abort-message-prefix)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x14/disp8      .                 # push *(ebp+20)
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . _write(2/stderr, error)
    # . . push args
    68/push  ": get: key not found: "/imm32
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . _write(2/stderr, key)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . _write(2/stderr, "\n")
    # . . push args
    68/push  Newline/imm32
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . syscall(exit, 1)
    bb/copy-to-ebx  1/imm32
    b8/copy-to-eax  1/imm32/exit
    cd/syscall  0x80/imm8
    # never gets here

test-get:
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # - setup: create a table with a couple of keys
    # var table/ecx : (stream {string, number} 16)  # 2 rows * 8 bytes/row
    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0x10/imm32        # subtract from esp
    68/push  0x10/imm32/length
    68/push  0/imm32/read
    68/push  0/imm32/write
    89/copy                         3/mod/direct    1/rm32/ecx    .           .             .           4/r32/esp   .               .                 # copy esp to ecx
    # insert(table, "code", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "code"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-insert/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # insert(table, "data", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "data"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-insert/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get:check1:
    # eax = get(table, "code", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "code"/imm32
    51/push-ecx
    # . . call
    e8/call  get/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax - table->data, 4, msg)
    # . check-ints-equal(eax - table, 16, msg)
    # . . push args
    68/push  "F - test-get/0"/imm32
    68/push  0x10/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get:check2:
    # eax = get(table, "data", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "data"/imm32
    51/push-ecx
    # . . call
    e8/call  get/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax - table->data, 12, msg)
    # . check-ints-equal(eax - table, 24, msg)
    # . . push args
    68/push  "F - test-get/1"/imm32
    68/push  0x18/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get:end:
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

# if no row is found, abort
get-slice:  # table : (addr stream {string_key, T}), key : (addr slice), row-size : int, abort-message-prefix : (addr array byte) -> eax : (addr T)
    # pseudocode:
    #   curr = table->data
    #   max = &table->data[table->write]
    #   while curr < max
    #     if slice-equal?(key, *curr)
    #       return curr+4
    #     curr += row-size
    #   abort
    #
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # . save registers
    51/push-ecx
    52/push-edx
    56/push-esi
    # esi = table
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
    # var curr/ecx : (addr string_key) = table->data
    8d/copy-address                 1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   0xc/disp8       .                 # copy esi+12 to ecx
    # var max/edx : (addr byte) = &table->data[table->write]
    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           2/r32/edx   .               .                 # copy *esi to edx
    8d/copy-address                 0/mod/indirect  4/rm32/sib    1/base/ecx  2/index/edx   .           2/r32/edx   .               .                 # copy ecx+edx to edx
$get-slice:search-loop:
    # if (curr >= max) abort
    39/compare                      3/mod/direct    1/rm32/ecx    .           .             .           2/r32/edx   .               .                 # compare ecx with edx
    73/jump-if-greater-or-equal-unsigned  $get-slice:abort/disp8
    # if (slice-equal?(key, *curr)) return curr+4
    # . eax = slice-equal?(key, *curr)
    # . . push args
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    # . . call
    e8/call  slice-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . if (eax != false) return eax = curr+4
    3d/compare-eax-and  0/imm32/false
    74/jump-if-equal  $get-slice:mismatch/disp8
    8d/copy-address                 1/mod/*+disp8   1/rm32/ecx    .           .             .           0/r32/eax   4/disp8         .                 # copy ecx+4 to eax
    eb/jump  $get-slice:end/disp8
$get-slice:mismatch:
    # curr += row-size
    03/add                          1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # add *(ebp+16) to ecx
    # loop
    eb/jump  $get-slice:search-loop/disp8
$get-slice:end:
    # . restore registers
    5e/pop-to-esi
    5a/pop-to-edx
    59/pop-to-ecx
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

$get-slice:abort:
    # . _write(2/stderr, abort-message-prefix)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x14/disp8      .                 # push *(ebp+20)
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . _write(2/stderr, error)
    # . . push args
    68/push  ": get-slice: key not found: "/imm32
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . write-slice-buffered(Stderr, key)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    68/push  Stderr/imm32
    # . . call
    e8/call  write-slice-buffered/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . flush(Stderr)
    # . . push args
    68/push  Stderr/imm32
    # . . call
    e8/call  flush/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
    # . _write(2/stderr, "\n")
    # . . push args
    68/push  Newline/imm32
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . syscall(exit, 1)
    bb/copy-to-ebx  1/imm32
    b8/copy-to-eax  1/imm32/exit
    cd/syscall  0x80/imm8
    # never gets here

test-get-slice:
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # - setup: create a table with a couple of keys
    # var table/ecx : (stream {string, number} 16)  # 2 rows * 8 bytes/row
    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0x10/imm32        # subtract from esp
    68/push  0x10/imm32/length
    68/push  0/imm32/read
    68/push  0/imm32/write
    89/copy                         3/mod/direct    1/rm32/ecx    .           .             .           4/r32/esp   .               .                 # copy esp to ecx
    # insert(table, "code", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "code"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-insert/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # insert(table, "data", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "data"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-insert/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-slice:check1:
    # (eax..edx) = "code"
    b8/copy-to-eax  "code"/imm32
    8b/copy                         0/mod/indirect  0/rm32/eax    .           .             .           2/r32/edx   .               .                 # copy *eax to edx
    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/eax  2/index/edx   .           2/r32/edx   4/disp8         .                 # copy eax+edx+4 to edx
    05/add-to-eax  4/imm32
    # var slice/edx : slice = {eax, edx}
    52/push-edx
    50/push-eax
    89/copy                         3/mod/direct    2/rm32/edx    .           .             .           4/r32/esp   .               .                 # copy esp to edx
    # eax = get-slice(table, "code", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    52/push-edx
    51/push-ecx
    # . . call
    e8/call  get-slice/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax - table->data, 4, msg)  # first row's value slot returned
    # . check-ints-equal(eax - table, 16, msg)
    # . . push args
    68/push  "F - test-get-slice/0"/imm32
    68/push  0x10/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-slice:check2:
    # (eax..edx) = "data"
    b8/copy-to-eax  "data"/imm32
    8b/copy                         0/mod/indirect  0/rm32/eax    .           .             .           2/r32/edx   .               .                 # copy *eax to edx
    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/eax  2/index/edx   .           2/r32/edx   4/disp8         .                 # copy eax+edx+4 to edx
    05/add-to-eax  4/imm32
    # var slice/edx : slice = {eax, edx}
    52/push-edx
    50/push-eax
    89/copy                         3/mod/direct    2/rm32/edx    .           .             .           4/r32/esp   .               .                 # copy esp to edx
    # eax = get-slice(table, "data" slice, 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    52/push-edx
    51/push-ecx
    # . . call
    e8/call  get-slice/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax - table->data, 12, msg)
    # . check-ints-equal(eax - table, 24, msg)
    # . . push args
    68/push  "F - test-get-slice/1"/imm32
    68/push  0x18/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-slice:end:
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

# if no row is found, save 'key' to the next available row
# if there are no rows free, abort
# return the address of the value
# Beware: assume keys are immutable; they're inserted by reference
# TODO: pass in an allocation descriptor
get-or-insert:  # table : (addr stream {string_key, T}), key : string_key, row-size : int -> eax : (addr T)
    # pseudocode:
    #   curr = table->data
    #   max = &table->data[table->write]
    #   while curr < max
    #     if string-equal?(key, *curr)
    #       return curr+4
    #     curr += row-size
    #   if table->write >= table->length
    #     abort
    #   zero-out(max, row-size)
    #   *max = key
    #   table->write += row-size
    #   return max+4
    #
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # . save registers
    51/push-ecx
    52/push-edx
    56/push-esi
    # esi = table
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
    # var curr/ecx : (addr string_key) = table->data
    8d/copy-address                 1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   0xc/disp8       .                 # copy esi+12 to ecx
    # var max/edx : (addr string_key) = &table->data[table->write]
    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           2/r32/edx   .               .                 # copy *esi to edx
    8d/copy-address                 0/mod/indirect  4/rm32/sib    1/base/ecx  2/index/edx   .           2/r32/edx   .               .                 # copy ecx+edx to edx
$get-or-insert:search-loop:
    # if (curr >= max) break
    39/compare                      3/mod/direct    1/rm32/ecx    .           .             .           2/r32/edx   .               .                 # compare ecx with edx
    73/jump-if-greater-or-equal-unsigned  $get-or-insert:not-found/disp8
    # if (string-equal?(key, *curr)) return curr+4
    # . eax = string-equal?(key, *curr)
    # . . push args
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    # . . call
    e8/call  string-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . if (eax != false) return eax = curr+4
    3d/compare-eax-and  0/imm32/false
    74/jump-if-equal  $get-or-insert:mismatch/disp8
    8d/copy-address                 1/mod/*+disp8   1/rm32/ecx    .           .             .           0/r32/eax   4/disp8         .                 # copy ecx+4 to eax
    eb/jump  $get-or-insert:end/disp8
$get-or-insert:mismatch:
    # curr += row-size
    03/add                          1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # add *(ebp+16) to ecx
    # loop
    eb/jump  $get-or-insert:search-loop/disp8
$get-or-insert:not-found:
    # result/eax = 0
    31/xor                          3/mod/direct    0/rm32/eax    .           .             .           0/r32/eax   .               .                 # clear eax
    # if (table->write >= table->length) abort
    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           1/r32/ecx   .               .                 # copy *esi to ecx
    3b/compare                      1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   8/disp8         .                 # compare ecx with *(esi+8)
    73/jump-if-greater-or-equal-unsigned  $get-or-insert:abort/disp8
    # zero-out(max, row-size)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x10/disp8      .                 # push *(ebp+16)
    52/push-edx
    # . . call
    e8/call  zero-out/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # *max = key
    # . eax = key
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
    # . *max = eax
    89/copy                         0/mod/indirect  2/rm32/edx    .           .             .           0/r32/eax   .               .                 # copy eax to *edx
    # table->write += row-size
    # . eax = row-size
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0x10/disp8      .                 # copy *(ebp+16) to eax
    # . table->write += eax
    01/add                          0/mod/indirect  6/rm32/esi    .           .             .           0/r32/eax   .               .                 # add eax to *esi
    # return max+4
    # . eax = max
    89/copy                         3/mod/direct    0/rm32/eax    .           .             .           2/r32/edx   .               .                 # copy edx to eax
    # . eax += 4
    05/add-to-eax  4/imm32
$get-or-insert:end:
    # . restore registers
    5e/pop-to-esi
    5a/pop-to-edx
    59/pop-to-ecx
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

$get-or-insert:abort:
    # . _write(2/stderr, error)
    # . . push args
    68/push  "get-or-insert: table is full\n"/imm32
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . syscall(exit, 1)
    bb/copy-to-ebx  1/imm32
    b8/copy-to-eax  1/imm32/exit
    cd/syscall  0x80/imm8
    # never gets here

test-get-or-insert:
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # var table/ecx : (stream {string, number} 16)  # 2 rows * 8 bytes/row
    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0x10/imm32        # subtract from esp
    68/push  0x10/imm32/length
    68/push  0/imm32/read
    68/push  0/imm32/write
    89/copy                         3/mod/direct    1/rm32/ecx    .           .             .           4/r32/esp   .               .                 # copy esp to ecx
$test-get-or-insert:first-call:
    # - start with an empty table, insert one key, verify that it was inserted
    # eax = get-or-insert(table, "code", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "code"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-insert/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax - table->data, 4, msg)  # first row's value slot returned
    # . check-ints-equal(eax - table, 16, msg)
    # . . push args
    68/push  "F - test-get-or-insert/0"/imm32
    68/push  0x10/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-or-insert:check2:
    # check-ints-equal(table->write, row-size = 8, msg)
    # . . push args
    68/push  "F - test-get-or-insert/1"/imm32
    68/push  8/imm32/row-size
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-strings-equal(*table->data, "code", msg)
    # . . push args
    68/push  "F - test-get-or-insert/2"/imm32
    68/push  "code"/imm32
    ff          6/subop/push        1/mod/*+disp8   1/rm32/ecx    .           .             .           .           0xc/disp8       .                 # push *(ecx+12)
    # . . call
    e8/call  check-strings-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-or-insert:second-call:
    # - insert the same key again, verify that it was reused
    # eax = get-or-insert(table, "code", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "code"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-insert/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax - table->data, 4, msg)
    # . check-ints-equal(eax - table, 16, msg)
    # . . push args
    68/push  "F - test-get-or-insert/3"/imm32
    68/push  0x10/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # no new row inserted
    # . check-ints-equal(table->write, row-size = 8, msg)
    # . . push args
    68/push  "F - test-get-or-insert/4"/imm32
    68/push  8/imm32/row-size
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-strings-equal(*table->data, "code", msg)
    # . . push args
    68/push  "F - test-get-or-insert/5"/imm32
    68/push  "code"/imm32
    ff          6/subop/push        1/mod/*+disp8   1/rm32/ecx    .           .             .           .           0xc/disp8       .                 # push *(ecx+12)
    # . . call
    e8/call  check-strings-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-or-insert:third-call:
    # - insert a new key, verify that it was inserted
    # eax = get-or-insert(table, "data", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "data"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-insert/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # table gets a new row
    # check-ints-equal(eax - table->data, 12, msg)  # second row's value slot returned
    # . check-ints-equal(eax - table, 24, msg)
    # . . push args
    68/push  "F - test-get-or-insert/6"/imm32
    68/push  0x18/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(table->write, 2 rows = 16, msg)
    # . . push args
    68/push  "F - test-get-or-insert/7"/imm32
    68/push  0x10/imm32/two-rows
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-strings-equal(*table->data+8, "data", msg)
    # check-strings-equal(*(table+20), "data", msg)
    # . . push args
    68/push  "F - test-get-or-insert/8"/imm32
    68/push  "data"/imm32
    ff          6/subop/push        1/mod/*+disp8   1/rm32/ecx    .           .             .           .           0x14/disp8      .                 # push *(ecx+20)
    # . . call
    e8/call  check-strings-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-or-insert:end:
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

# if no row is found, save 'key' in the next available row
# if there are no rows free, abort
# WARNING: leaks memory
# TODO: pass in an allocation descriptor
leaky-get-or-insert-slice:  # table : (addr stream {string_key, T}), key : (addr slice), row-size : int -> eax : (addr T)
    # pseudocode:
    #   curr = table->data
    #   max = &table->data[table->write]
    #   while curr < max
    #     if slice-equal?(key, *curr)
    #       return curr+4
    #     curr += row-size
    #   if table->write >= table->length
    #     abort
    #   zero-out(max, row-size)
    #   *max = slice-to-string(Heap, key)
    #   table->write += row-size
    #   return max+4
    #
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # . save registers
    51/push-ecx
    52/push-edx
    56/push-esi
    # esi = table
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
    # var curr/ecx : (addr string_key) = table->data
    8d/copy-address                 1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   0xc/disp8       .                 # copy esi+12 to ecx
    # var max/edx : (addr string_key) = &table->data[table->write]
    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           2/r32/edx   .               .                 # copy *esi to edx
    8d/copy-address                 0/mod/indirect  4/rm32/sib    1/base/ecx  2/index/edx   .           2/r32/edx   .               .                 # copy ecx+edx to edx
$leaky-get-or-insert-slice:search-loop:
    # if (curr >= max) break
    39/compare                      3/mod/direct    1/rm32/ecx    .           .             .           2/r32/edx   .               .                 # compare ecx with edx
    73/jump-if-greater-or-equal-unsigned  $leaky-get-or-insert-slice:not-found/disp8
    # if (slice-equal?(key, *curr)) return curr+4
    # . eax = slice-equal?(key, *curr)
    # . . push args
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    # . . call
    e8/call  slice-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . if (eax != false) return eax = curr+4
    3d/compare-eax-and  0/imm32/false
    74/jump-if-equal  $leaky-get-or-insert-slice:mismatch/disp8
    8d/copy-address                 1/mod/*+disp8   1/rm32/ecx    .           .             .           0/r32/eax   4/disp8         .                 # copy ecx+4 to eax
    eb/jump  $leaky-get-or-insert-slice:end/disp8
$leaky-get-or-insert-slice:mismatch:
    # curr += row-size
    03/add                          1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # add *(ebp+16) to ecx
    # loop
    eb/jump  $leaky-get-or-insert-slice:search-loop/disp8
$leaky-get-or-insert-slice:not-found:
    # result/eax = 0
    31/xor                          3/mod/direct    0/rm32/eax    .           .             .           0/r32/eax   .               .                 # clear eax
    # if (table->write >= table->length) abort
    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           1/r32/ecx   .               .                 # copy *esi to ecx
    3b/compare                      1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   8/disp8         .                 # compare ecx with *(esi+8)
    7d/jump-if-greater-or-equal  $leaky-get-or-insert-slice:abort/disp8
    # zero-out(max, row-size)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x10/disp8      .                 # push *(ebp+16)
    52/push-edx
    # . . call
    e8/call  zero-out/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # *max = slice-to-string(Heap, key)
    # . eax = slice-to-string(Heap, key)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    68/push  Heap/imm32
    # . . call
    e8/call  slice-to-string/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . *max = eax
    89/copy                         0/mod/indirect  2/rm32/edx    .           .             .           0/r32/eax   .               .                 # copy eax to *edx
    # table->write += row-size
    # . eax = row-size
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0x10/disp8      .                 # copy *(ebp+16) to eax
    # . table->write += eax
    01/add                          0/mod/indirect  6/rm32/esi    .           .             .           0/r32/eax   .               .                 # add eax to *esi
    # return max+4
    # . eax = max
    89/copy                         3/mod/direct    0/rm32/eax    .           .             .           2/r32/edx   .               .                 # copy edx to eax
    # . eax += 4
    05/add-to-eax  4/imm32
$leaky-get-or-insert-slice:end:
    # . restore registers
    5e/pop-to-esi
    5a/pop-to-edx
    59/pop-to-ecx
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

$leaky-get-or-insert-slice:abort:
    # . _write(2/stderr, error)
    # . . push args
    68/push  "leaky-get-or-insert-slice: table is full\n"/imm32
    68/push  2/imm32/stderr
    # . . call
    e8/call  _write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . syscall(exit, 1)
    bb/copy-to-ebx  1/imm32
    b8/copy-to-eax  1/imm32/exit
    cd/syscall  0x80/imm8
    # never gets here

test-leaky-get-or-insert-slice:
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # var table/ecx : (stream {string, number} 16)  # 2 rows * 8 bytes/row
    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0x10/imm32        # subtract from esp
    68/push  0x10/imm32/length
    68/push  0/imm32/read
    68/push  0/imm32/write
    89/copy                         3/mod/direct    1/rm32/ecx    .           .             .           4/r32/esp   .               .                 # copy esp to ecx
    # (eax..edx) = "code"
    b8/copy-to-eax  "code"/imm32
    8b/copy                         0/mod/indirect  0/rm32/eax    .           .             .           2/r32/edx   .               .                 # copy *eax to edx
    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/eax  2/index/edx   .           2/r32/edx   4/disp8         .                 # copy eax+edx+4 to edx
    05/add-to-eax  4/imm32
    # var slice/edx : slice = {eax, edx}
    52/push-edx
    50/push-eax
    89/copy                         3/mod/direct    2/rm32/edx    .           .             .           4/r32/esp   .               .                 # copy esp to edx
$test-leaky-get-or-insert-slice:first-call:
    # - start with an empty table, insert one key, verify that it was inserted
    # eax = leaky-get-or-insert-slice(table, "code" slice, 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    52/push-edx
    51/push-ecx
    # . . call
    e8/call  leaky-get-or-insert-slice/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax - table->data, 4, msg)  # first row's value slot returned
    # . check-ints-equal(eax - table, 16, msg)
    # . . push args
    68/push  "F - test-leaky-get-or-insert-slice/0"/imm32
    68/push  0x10/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-leaky-get-or-insert-slice:check2:
    # check-ints-equal(table->write, row-size = 8, msg)
    # . . push args
    68/push  "F - test-leaky-get-or-insert-slice/1"/imm32
    68/push  8/imm32/row-size
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-strings-equal(*table->data, "code", msg)
    # . . push args
    68/push  "F - test-leaky-get-or-insert-slice/2"/imm32
    68/push  "code"/imm32
    ff          6/subop/push        1/mod/*+disp8   1/rm32/ecx    .           .             .           .           0xc/disp8       .                 # push *(ecx+12)
    # . . call
    e8/call  check-strings-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-leaky-get-or-insert-slice:second-call:
    # - insert the same key again, verify that it was reused
    # eax = leaky-get-or-insert-slice(table, "code" slice, 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    52/push-edx
    51/push-ecx
    # . . call
    e8/call  leaky-get-or-insert-slice/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax - table->data, 4, msg)
    # . check-ints-equal(eax - table, 16, msg)
    # . . push args
    68/push  "F - test-leaky-get-or-insert-slice/3"/imm32
    68/push  0x10/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # no new row inserted
    # . check-ints-equal(table->write, row-size = 8, msg)
    # . . push args
    68/push  "F - test-leaky-get-or-insert-slice/4"/imm32
    68/push  8/imm32/row-size
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-strings-equal(*table->data, "code", msg)
    # . . push args
    68/push  "F - test-leaky-get-or-insert-slice/5"/imm32
    68/push  "code"/imm32
    ff          6/subop/push        1/mod/*+disp8   1/rm32/ecx    .           .             .           .           0xc/disp8       .                 # push *(ecx+12)
    # . . call
    e8/call  check-strings-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-leaky-get-or-insert-slice:third-call:
    # - insert a new key, verify that it was inserted
    # (eax..edx) = "data"
    b8/copy-to-eax  "data"/imm32
    8b/copy                         0/mod/indirect  0/rm32/eax    .           .             .           2/r32/edx   .               .                 # copy *eax to edx
    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/eax  2/index/edx   .           2/r32/edx   4/disp8         .                 # copy eax+edx+4 to edx
    05/add-to-eax  4/imm32
    # var slice/edx : slice = {eax, edx}
    52/push-edx
    50/push-eax
    89/copy                         3/mod/direct    2/rm32/edx    .           .             .           4/r32/esp   .               .                 # copy esp to edx
    # eax = leaky-get-or-insert-slice(table, "data" slice, 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    52/push-edx
    51/push-ecx
    # . . call
    e8/call  leaky-get-or-insert-slice/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # table gets a new row
    # check-ints-equal(eax - table->data, 12, msg)  # second row's value slot returned
    # . check-ints-equal(eax - table, 24, msg)
    # . . push args
    68/push  "F - test-leaky-get-or-insert-slice/6"/imm32
    68/push  0x18/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(table->write, 2 rows = 16, msg)
    # . . push args
    68/push  "F - test-leaky-get-or-insert-slice/7"/imm32
    68/push  0x10/imm32/two-rows
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-strings-equal(*table->data+8, "data", msg)
    # check-strings-equal(*(table+20), "data", msg)
    # . . push args
    68/push  "F - test-leaky-get-or-insert-slice/8"/imm32
    68/push  "data"/imm32
    ff          6/subop/push        1/mod/*+disp8   1/rm32/ecx    .           .             .           .           0x14/disp8      .                 # push *(ecx+20)
    # . . call
    e8/call  check-strings-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-leaky-get-or-insert-slice:end:
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

# if no row is found, stop(ed)
get-or-stop:  # table : (addr stream {string_key, T}), key : string_key, row-size : int,
              # abort-message-prefix : (addr array byte), err : (addr buffered-file), ed : (addr exit-descriptor)
              # -> eax : (addr T)
    # pseudocode:
    #   curr = table->data
    #   max = &table->data[table->write]
    #   while curr < max
    #     if string-equal?(key, *curr)
    #       return curr+4
    #     curr += row-size
    #   write-buffered(err, msg)
    #   stop(ed)
    #
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # . save registers
    51/push-ecx
    52/push-edx
    56/push-esi
    # esi = table
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
    # var curr/ecx : (addr string_key) = table->data
    8d/copy-address                 1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   0xc/disp8       .                 # copy esi+12 to ecx
    # var max/edx : (addr byte) = &table->data[table->write]
    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           2/r32/edx   .               .                 # copy *esi to edx
    8d/copy-address                 0/mod/indirect  4/rm32/sib    1/base/ecx  2/index/edx   .           2/r32/edx   .               .                 # copy ecx+edx to edx
$get-or-stop:search-loop:
    # if (curr >= max) stop(ed)
    39/compare                      3/mod/direct    1/rm32/ecx    .           .             .           2/r32/edx   .               .                 # compare ecx with edx
    73/jump-if-greater-or-equal-unsigned  $get-or-stop:stop/disp8
    # if (string-equal?(key, *curr)) return curr+4
    # . eax = string-equal?(key, *curr)
    # . . push args
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    # . . call
    e8/call  string-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . if (eax != false) return eax = curr+4
    3d/compare-eax-and  0/imm32/false
    74/jump-if-equal  $get-or-stop:mismatch/disp8
    8d/copy-address                 1/mod/*+disp8   1/rm32/ecx    .           .             .           0/r32/eax   4/disp8         .                 # copy ecx+4 to eax
    eb/jump  $get-or-stop:end/disp8
$get-or-stop:mismatch:
    # curr += row-size
    03/add                          1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # add *(ebp+16) to ecx
    # loop
    eb/jump  $get-or-stop:search-loop/disp8
$get-or-stop:end:
    # . restore registers
    5e/pop-to-esi
    5a/pop-to-edx
    59/pop-to-ecx
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

$get-or-stop:stop:
    # . write-buffered(err, abort-message-prefix)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x14/disp8      .                 # push *(ebp+20)
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x18/disp8      .                 # push *(ebp+24)
    # . . call
    e8/call  write-buffered/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . write-buffered(err, error)
    # . . push args
    68/push  ": get-or-stop: key not found: "/imm32
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x18/disp8      .                 # push *(ebp+24)
    # . . call
    e8/call  write-buffered/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . write-buffered(err, key)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x18/disp8      .                 # push *(ebp+24)
    # . . call
    e8/call  write-buffered/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . write-buffered(err, "\n")
    # . . push args
    68/push  Newline/imm32
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x18/disp8      .                 # push *(ebp+24)
    # . . call
    e8/call  write-buffered/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . stop(ed, 1)
    # . . push args
    68/push  1/imm32
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x1c/disp8      .                 # push *(ebp+28)
    # . . call
    e8/call  stop/disp32
    # never gets here
$get-or-stop:terminus:
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # syscall(exit, 1)
    b8/copy-to-eax  1/imm32/exit
    cd/syscall  0x80/imm8

test-get-or-stop:
    # This test uses exit-descriptors. Use ebp for setting up local variables.
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # setup
    # . clear-stream(_test-error-stream)
    # . . push args
    68/push  _test-error-stream/imm32
    # . . call
    e8/call  clear-stream/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
    # . clear-stream($_test-error-buffered-file->buffer)
    # . . push args
    68/push  $_test-error-buffered-file->buffer/imm32
    # . . call
    e8/call  clear-stream/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
    # var table/ecx : (stream {string, number} 16)  # 2 rows * 8 bytes/row
    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0x10/imm32        # subtract from esp
    68/push  0x10/imm32/length
    68/push  0/imm32/read
    68/push  0/imm32/write
    89/copy                         3/mod/direct    1/rm32/ecx    .           .             .           4/r32/esp   .               .                 # copy esp to ecx
    # var ed/edx : exit-descriptor
    68/push  0/imm32
    68/push  0/imm32
    89/copy                         3/mod/direct    2/rm32/edx    .           .             .           4/r32/esp   .               .                 # copy esp to edx
    # size 'ed' for the calls to 'get-or-stop'
    # . tailor-exit-descriptor(ed, 24)
    # . . push args
    68/push  0x18/imm32/nbytes-of-args-for-get-or-stop
    52/push-edx
    # . . call
    e8/call  tailor-exit-descriptor/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # insert(table, "code", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "code"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-insert/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-or-stop:success:
    # eax = get-or-stop(table, "code", row-size=8, msg, _test-error-buffered-file, ed)
    # . . push args
    52/push-edx/ed
    68/push  _test-error-buffered-file/imm32
    68/push  "foo"/imm32/abort-prefix
    68/push  8/imm32/row-size
    68/push  "code"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-stop/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x18/imm32        # add to esp
$test-get-or-stop:success-assertion:
    # check-ints-equal(eax - table->data, 4, msg)
    # . check-ints-equal(eax - table, 16, msg)
    # . . push args
    68/push  "F - test-get-or-stop/0"/imm32
    68/push  0x10/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-or-stop:failure:
    # eax = get-or-stop(table, "data", row-size=8, msg, _test-error-buffered-file, ed)
    # . . push args
    52/push-edx/ed
    68/push  _test-error-buffered-file/imm32
    68/push  "foo"/imm32/abort-prefix
    68/push  8/imm32/row-size
    68/push  "data"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-stop/disp32
    # registers except esp may be clobbered at this point
    # restore register args, discard others
    59/pop-to-ecx
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x10/imm32        # add to esp
    5a/pop-to-edx
$test-get-or-stop:failure-assertion:
    # check that get-or-stop tried to call stop(1)
    # . check-ints-equal(ed->value, 2, msg)
    # . . push args
    68/push  "F - test-get-or-stop/1"/imm32
    68/push  2/imm32
    # . . push ed->value
    ff          6/subop/push        1/mod/*+disp8   2/rm32/edx    .           .             .           .           4/disp8         .                 # push *(edx+4)
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-or-stop:end:
    # . epilogue
    # don't restore esp from ebp; manually reclaim locals
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x24/imm32        # add to esp
    5d/pop-to-ebp
    c3/return

# if no row is found, stop(ed)
get-slice-or-stop:  # table : (addr stream {string_key, _}), key : (addr slice), row-size : int,
                    # abort-message-prefix : (addr string), err : (addr buffered-file), ed : (addr exit-descriptor)
                    # -> eax : (addr _)
    # pseudocode:
    #   curr = table->data
    #   max = &table->data[table->write]
    #   while curr < max
    #     if slice-equal?(key, *curr)
    #       return curr+4
    #     curr += row-size
    #   write-buffered(err, msg)
    #   stop(ed)
    #
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # . save registers
    51/push-ecx
    52/push-edx
    56/push-esi
    # esi = table
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
    # var curr/ecx : (addr string_key) = table->data
    8d/copy-address                 1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   0xc/disp8       .                 # copy esi+12 to ecx
    # var max/edx : (addr byte) = &table->data[table->write]
    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           2/r32/edx   .               .                 # copy *esi to edx
    8d/copy-address                 0/mod/indirect  4/rm32/sib    1/base/ecx  2/index/edx   .           2/r32/edx   .               .                 # copy ecx+edx to edx
$get-slice-or-stop:search-loop:
    # if (curr >= max) stop(ed)
    39/compare                      3/mod/direct    1/rm32/ecx    .           .             .           2/r32/edx   .               .                 # compare ecx with edx
    73/jump-if-greater-or-equal-unsigned  $get-slice-or-stop:stop/disp8
    # if (slice-equal?(key, *curr)) return curr+4
    # . eax = slice-equal?(key, *curr)
    # . . push args
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    # . . call
    e8/call  slice-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . if (eax != false) return eax = curr+4
    3d/compare-eax-and  0/imm32/false
    74/jump-if-equal  $get-slice-or-stop:mismatch/disp8
    8d/copy-address                 1/mod/*+disp8   1/rm32/ecx    .           .             .           0/r32/eax   4/disp8         .                 # copy ecx+4 to eax
    eb/jump  $get-slice-or-stop:end/disp8
$get-slice-or-stop:mismatch:
    # curr += row-size
    03/add                          1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # add *(ebp+16) to ecx
    # loop
    eb/jump  $get-slice-or-stop:search-loop/disp8
$get-slice-or-stop:end:
    # . restore registers
    5e/pop-to-esi
    5a/pop-to-edx
    59/pop-to-ecx
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

$get-slice-or-stop:stop:
    # . write-buffered(err, abort-message-prefix)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x14/disp8      .                 # push *(ebp+20)
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x18/disp8      .                 # push *(ebp+24)
    # . . call
    e8/call  write-buffered/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . write-buffered(err, error)
    # . . push args
    68/push  ": get-slice-or-stop: key not found: "/imm32
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x18/disp8      .                 # push *(ebp+24)
    # . . call
    e8/call  write-buffered/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . write-slice-buffered(err, key)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x18/disp8      .                 # push *(ebp+24)
    # . . call
    e8/call  write-slice-buffered/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . write-buffered(err, "\n")
    # . . push args
    68/push  Newline/imm32
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x18/disp8      .                 # push *(ebp+24)
    # . . call
    e8/call  write-buffered/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . stop(ed, 1)
    # . . push args
    68/push  1/imm32
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x1c/disp8      .                 # push *(ebp+28)
    # . . call
    e8/call  stop/disp32
    # never gets here
$get-slice-or-stop:terminus:
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # syscall(exit, 1)
    b8/copy-to-eax  1/imm32/exit
    cd/syscall  0x80/imm8

test-get-slice-or-stop:
    # This test uses exit-descriptors. Use ebp for setting up local variables.
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # setup
    # . clear-stream(_test-error-stream)
    # . . push args
    68/push  _test-error-stream/imm32
    # . . call
    e8/call  clear-stream/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
    # . clear-stream($_test-error-buffered-file->buffer)
    # . . push args
    68/push  $_test-error-buffered-file->buffer/imm32
    # . . call
    e8/call  clear-stream/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
    # var table/ecx : (stream {string, number} 16)  # 2 rows * 8 bytes/row
    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0x10/imm32        # subtract from esp
    68/push  0x10/imm32/length
    68/push  0/imm32/read
    68/push  0/imm32/write
    89/copy                         3/mod/direct    1/rm32/ecx    .           .             .           4/r32/esp   .               .                 # copy esp to ecx
    # var ed/edx : exit-descriptor
    68/push  0/imm32
    68/push  0/imm32
    89/copy                         3/mod/direct    2/rm32/edx    .           .             .           4/r32/esp   .               .                 # copy esp to edx
    # var slice/ebx : slice = "code"
    # . (eax..ebx) = "code"
    b8/copy-to-eax  "code"/imm32
    8b/copy                         0/mod/indirect  0/rm32/eax    .           .             .           3/r32/ebx   .               .                 # copy *eax to ebx
    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/eax  3/index/ebx   .           3/r32/ebx   4/disp8         .                 # copy eax+ebx+4 to ebx
    05/add-to-eax  4/imm32
    # . ebx = {eax, ebx}
    53/push-ebx
    50/push-eax
    89/copy                         3/mod/direct    3/rm32/ebx    .           .             .           4/r32/esp   .               .                 # copy esp to ebx
    # size 'ed' for the calls to 'get-or-stop' (define no locals past this point)
    # . tailor-exit-descriptor(ed, 24)
    # . . push args
    68/push  0x18/imm32/nbytes-of-args-for-get-or-stop
    52/push-edx
    # . . call
    e8/call  tailor-exit-descriptor/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # insert(table, "code", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "code"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-insert/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-slice-or-stop:success:
    # eax = get-slice-or-stop(table, slice, row-size=8, msg, _test-error-buffered-file, ed)
    # . . push args
    52/push-edx/ed
    68/push  _test-error-buffered-file/imm32
    68/push  "foo"/imm32/abort-prefix
    68/push  8/imm32/row-size
    53/push-ebx/slice
    51/push-ecx
    # . . call
    e8/call  get-slice-or-stop/disp32
    # registers except esp may be clobbered at this point
    # restore register args, discard others
    59/pop-to-ecx
    5b/pop-to-ebx
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    5a/pop-to-edx
$test-get-slice-or-stop:success-assertion:
    # check-ints-equal(eax - table->data, 4, msg)  # first row's value slot returned
    # . check-ints-equal(eax - table, 16, msg)
    # . . push args
    68/push  "F - test-get-slice-or-stop/0"/imm32
    68/push  0x10/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-slice-or-stop:failure:
    # slice = "segment2"
    # . *ebx = "segment2"->data
    b8/copy-to-eax  "segment2"/imm32
    05/add-to-eax  4/imm32
    89/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to *ebx
    # . *(ebx+4) = "segment2"->data + len("segment2")
    05/add-to-eax  8/imm32/strlen
    89/copy                         1/mod/*+disp8   3/rm32/ebx    .           .             .           0/r32/eax   4/disp8         .                 # copy eax to *(ebx+4)
    # eax = get-slice-or-stop(table, slice, row-size=8, msg, _test-error-buffered-file, ed)
    # . . push args
    52/push-edx/ed
    68/push  _test-error-buffered-file/imm32
    68/push  "foo"/imm32/abort-prefix
    68/push  8/imm32/row-size
    53/push-ebx/slice
    51/push-ecx
    # . . call
    e8/call  get-slice-or-stop/disp32
    # registers except esp may be clobbered at this point
    # restore register args, discard others
    59/pop-to-ecx
    5b/pop-to-ebx
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    5a/pop-to-edx
$test-get-slice-or-stop:failure-assertion:
    # check that get-or-stop tried to call stop(1)
    # . check-ints-equal(ed->value, 2, msg)
    # . . push args
    68/push  "F - test-get-or-stop/1"/imm32
    68/push  2/imm32
    # . . push ed->value
    ff          6/subop/push        1/mod/*+disp8   2/rm32/edx    .           .             .           .           4/disp8         .                 # push *(edx+4)
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-get-slice-or-stop:end:
    # . epilogue
    # don't restore esp from ebp; manually reclaim locals
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x2c/imm32        # add to esp
    5d/pop-to-ebp
    c3/return

# if no row is found, return null (0)
maybe-get:  # table : (addr stream {string_key, T}), key : string_key, row-size : int -> eax : (addr T)
    # pseudocode:
    #   curr = table->data
    #   max = &table->data[table->write]
    #   while curr < max
    #     if string-equal?(key, *curr)
    #       return curr+4
    #     curr += row-size
    #   return 0
    #
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # . save registers
    51/push-ecx
    52/push-edx
    56/push-esi
    # esi = table
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
    # var curr/ecx : (addr string_key) = table->data
    8d/copy-address                 1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   0xc/disp8       .                 # copy esi+12 to ecx
    # var max/edx : (addr byte) = &table->data[table->write]
    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           2/r32/edx   .               .                 # copy *esi to edx
    8d/copy-address                 0/mod/indirect  4/rm32/sib    1/base/ecx  2/index/edx   .           2/r32/edx   .               .                 # copy ecx+edx to edx
$maybe-get:search-loop:
    # if (curr >= max) return null
    39/compare                      3/mod/direct    1/rm32/ecx    .           .             .           2/r32/edx   .               .                 # compare ecx with edx
    73/jump-if-greater-or-equal-unsigned  $maybe-get:null/disp8
    # if (string-equal?(key, *curr)) return curr+4
    # . eax = string-equal?(key, *curr)
    # . . push args
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    # . . call
    e8/call  string-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . if (eax != false) return eax = curr+4
    3d/compare-eax-and  0/imm32/false
    74/jump-if-equal  $maybe-get:mismatch/disp8
    8d/copy-address                 1/mod/*+disp8   1/rm32/ecx    .           .             .           0/r32/eax   4/disp8         .                 # copy ecx+4 to eax
    eb/jump  $maybe-get:end/disp8
$maybe-get:mismatch:
    # curr += row-size
    03/add                          1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # add *(ebp+16) to ecx
    # loop
    eb/jump  $maybe-get:search-loop/disp8
$maybe-get:null:
    b8/copy-to-eax  0/imm32
$maybe-get:end:
    # . restore registers
    5e/pop-to-esi
    5a/pop-to-edx
    59/pop-to-ecx
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

test-maybe-get:
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # - setup: create a table with one row
    # var table/ecx : (stream {string, number} 16)   # 2 rows * 8 bytes/row
    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0x10/imm32        # subtract from esp
    68/push  0x10/imm32/length
    68/push  0/imm32/read
    68/push  0/imm32/write
    89/copy                         3/mod/direct    1/rm32/ecx    .           .             .           4/r32/esp   .               .                 # copy esp to ecx
    # eax = get-or-insert(table, "code", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "code"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-insert/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-maybe-get:success:
    # - check for the same key, verify that it was reused
    # eax = maybe-get(table, "code", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "code"/imm32
    51/push-ecx
    # . . call
    e8/call  maybe-get/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax - table->data, 4, msg)
    # . check-ints-equal(eax - table, 16, msg)
    # . . push args
    68/push  "F - test-maybe-get/0"/imm32
    68/push  0x10/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # no new row inserted
    # . check-ints-equal(table->write, row-size = 8, msg)
    # . . push args
    68/push  "F - test-maybe-get/1"/imm32
    68/push  8/imm32/row-size
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-strings-equal(*table->data, "code", msg)
    # . . push args
    68/push  "F - test-maybe-get/2"/imm32
    68/push  "code"/imm32
    ff          6/subop/push        1/mod/*+disp8   1/rm32/ecx    .           .             .           .           0xc/disp8       .                 # push *(ecx+12)
    # . . call
    e8/call  check-strings-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-maybe-get:failure:
    # - search for a new key
    # eax = maybe-get(table, "data", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "data"/imm32
    51/push-ecx
    # . . call
    e8/call  maybe-get/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax, 0, msg)
    # . . push args
    68/push  "F - test-maybe-get/3"/imm32
    68/push  0/imm32
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-maybe-get:end:
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

# if no row is found, return null (0)
maybe-get-slice:  # table : (addr stream {string_key, T}), key : (addr slice), row-size : int -> eax : (addr T)
    # pseudocode:
    #   curr = table->data
    #   max = &table->data[table->write]
    #   while curr < max
    #     if slice-equal?(key, *curr)
    #       return curr+4
    #     curr += row-size
    #   return 0
    #
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # . save registers
    51/push-ecx
    52/push-edx
    56/push-esi
    # esi = table
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
    # var curr/ecx : (addr string_key) = table->data
    8d/copy-address                 1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   0xc/disp8       .                 # copy esi+12 to ecx
    # var max/edx : (addr byte) = &table->data[table->write]
    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           2/r32/edx   .               .                 # copy *esi to edx
    8d/copy-address                 0/mod/indirect  4/rm32/sib    1/base/ecx  2/index/edx   .           2/r32/edx   .               .                 # copy ecx+edx to edx
$maybe-get-slice:search-loop:
    # if (curr >= max) return null
    39/compare                      3/mod/direct    1/rm32/ecx    .           .             .           2/r32/edx   .               .                 # compare ecx with edx
    73/jump-if-greater-or-equal-unsigned  $maybe-get-slice:null/disp8
    # if (slice-equal?(key, *curr)) return curr+4
    # . eax = slice-equal?(key, *curr)
    # . . push args
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
    # . . call
    e8/call  slice-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . if (eax != false) return eax = curr+4
    3d/compare-eax-and  0/imm32/false
    74/jump-if-equal  $maybe-get-slice:mismatch/disp8
    8d/copy-address                 1/mod/*+disp8   1/rm32/ecx    .           .             .           0/r32/eax   4/disp8         .                 # copy ecx+4 to eax
    eb/jump  $maybe-get-slice:end/disp8
$maybe-get-slice:mismatch:
    # curr += row-size
    03/add                          1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # add *(ebp+16) to ecx
    # loop
    eb/jump  $maybe-get-slice:search-loop/disp8
$maybe-get-slice:null:
    b8/copy-to-eax  0/imm32
$maybe-get-slice:end:
    # . restore registers
    5e/pop-to-esi
    5a/pop-to-edx
    59/pop-to-ecx
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

test-maybe-get-slice:
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # - setup: create a table with one row
    # var table/ecx : (stream {string, number} 16)   # 2 rows * 8 bytes/row
    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0x10/imm32        # subtract from esp
    68/push  0x10/imm32/length
    68/push  0/imm32/read
    68/push  0/imm32/write
    89/copy                         3/mod/direct    1/rm32/ecx    .           .             .           4/r32/esp   .               .                 # copy esp to ecx
    # insert(table, "code", 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    68/push  "code"/imm32
    51/push-ecx
    # . . call
    e8/call  get-or-insert/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-maybe-get-slice:success:
    # - check for the same key, verify that it was reused
    # (eax..edx) = "code"
    b8/copy-to-eax  "code"/imm32
    8b/copy                         0/mod/indirect  0/rm32/eax    .           .             .           2/r32/edx   .               .                 # copy *eax to edx
    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/eax  2/index/edx   .           2/r32/edx   4/disp8         .                 # copy eax+edx+4 to edx
    05/add-to-eax  4/imm32
    # var slice/edx : slice = {eax, edx}
    52/push-edx
    50/push-eax
    89/copy                         3/mod/direct    2/rm32/edx    .           .             .           4/r32/esp   .               .                 # copy esp to edx
    # eax = maybe-get-slice(table, "code" slice, 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    52/push-edx
    51/push-ecx
    # . . call
    e8/call  maybe-get-slice/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax - table->data, 4, msg)
    # . check-ints-equal(eax - table, 16, msg)
    # . . push args
    68/push  "F - test-maybe-get-slice/0"/imm32
    68/push  0x10/imm32
    29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # no new row inserted
    # . check-ints-equal(table->write, row-size = 8, msg)
    # . . push args
    68/push  "F - test-maybe-get-slice/1"/imm32
    68/push  8/imm32/row-size
    ff          6/subop/push        0/mod/indirect  1/rm32/ecx    .           .             .           .           .               .                 # push *ecx
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-strings-equal(*table->data, "code", msg)
    # . . push args
    68/push  "F - test-maybe-get-slice/2"/imm32
    68/push  "code"/imm32
    ff          6/subop/push        1/mod/*+disp8   1/rm32/ecx    .           .             .           .           0xc/disp8       .                 # push *(ecx+12)
    # . . call
    e8/call  check-strings-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-maybe-get-slice:failure:
    # - search for a new key
    # (eax..edx) = "data"
    b8/copy-to-eax  "data"/imm32
    8b/copy                         0/mod/indirect  0/rm32/eax    .           .             .           2/r32/edx   .               .                 # copy *eax to edx
    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/eax  2/index/edx   .           2/r32/edx   4/disp8         .                 # copy eax+edx+4 to edx
    05/add-to-eax  4/imm32
    # var slice/edx : slice = {eax, edx}
    52/push-edx
    50/push-eax
    89/copy                         3/mod/direct    2/rm32/edx    .           .             .           4/r32/esp   .               .                 # copy esp to edx
    # eax = maybe-get-slice(table, "data" slice, 8 bytes per row)
    # . . push args
    68/push  8/imm32/row-size
    52/push-edx
    51/push-ecx
    # . . call
    e8/call  maybe-get-slice/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # check-ints-equal(eax, 0, msg)
    # . . push args
    68/push  "F - test-maybe-get-slice/3"/imm32
    68/push  0/imm32
    50/push-eax
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
$test-maybe-get-slice:end:
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

# . . vim:nowrap:textwidth=0