https://github.com/akkartik/mu/blob/master/subx/apps/handle.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 == code
24
25
26
27
28
29 e8/call run-tests/disp32
30
31 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32
32 b8/copy-to-EAX 1/imm32/exit
33 cd/syscall 0x80/imm8
34
35 new:
36
37 55/push-EBP
38 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
39
40 50/push-EAX
41 51/push-ECX
42 52/push-EDX
43
44 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 0xc/disp8 .
45 81 0/subop/add 3/mod/direct 1/rm32/ECX . . . . . 4/imm32
46
47
48 51/push-ECX
49 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
50
51 e8/call allocate/disp32
52
53 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
54
55 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 2/r32/EDX 0x10/disp8 .
56
57 89/copy 1/mod/*+disp8 2/rm32/EDX . . . 0/r32/EAX 4/disp8 .
58
59 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0/imm32
60 75/jump-if-not-equal $new:continue/disp8
61 c7 0/subop/copy 0/mod/indirect 2/rm32/EDX . . . . . 0/imm32
62 eb/jump $new:end/disp8
63 $new:continue:
64
65
66 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 1/r32/ECX Next-alloc-id/disp32
67
68 89/copy 0/mod/indirect 0/rm32/EAX . . . 1/r32/ECX . .
69
70 89/copy 0/mod/indirect 2/rm32/EDX . . . 1/r32/ECX . .
71
72 ff 0/subop/increment 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32
73 $new:end:
74
75 5a/pop-to-EDX
76 59/pop-to-ECX
77 58/pop-to-EAX
78
79 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
80 5d/pop-to-EBP
81 c3/return
82
83 test-new:
84
85 55/push-EBP
86 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
87
88 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 0x34/imm32
89
90 68/push 0/imm32/address
91 68/push 0/imm32/alloc-id
92 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
93
94
95 51/push-ECX
96 68/push 2/imm32/size
97 68/push Heap/imm32
98
99 e8/call new/disp32
100
101 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
102
103
104 68/push "F - test-new: alloc id of handle"/imm32
105 68/push 0x34/imm32
106 ff 6/subop/push 0/mod/indirect 1/rm32/ECX . . . . . .
107
108 e8/call check-ints-equal/disp32
109
110 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
111
112
113 68/push "F - test-new: alloc id of payload"/imm32
114 68/push 0x34/imm32
115 8b/copy 1/mod/*+disp8 1/rm32/ECX . . . 2/r32/EDX 4/disp8 .
116 ff 6/subop/push 0/mod/indirect 2/rm32/EDX . . . . . .
117
118 e8/call check-ints-equal/disp32
119
120 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
121
122
123 68/push "F - test-new: next alloc id"/imm32
124 68/push 0x35/imm32
125 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32
126
127 e8/call check-ints-equal/disp32
128
129 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
130
131
132 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
133
134 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
135 5d/pop-to-EBP
136 c3/return
137
138 test-new-failure:
139
140 55/push-EBP
141 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
142
143 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 0x34/imm32
144
145
146 68/push 0x10/imm32/limit
147 68/push 0x10/imm32/curr
148 89/copy 3/mod/direct 0/rm32/EAX . . . 4/r32/ESP . .
149
150 68/push 1234/imm32/address
151 68/push 5678/imm32/alloc-id
152 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
153
154
155
156 51/push-ECX
157 68/push 2/imm32/size
158 50/push-EAX
159
160 e8/call new/disp32
161
162 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
163
164
165
166 68/push "F - test-new-failure: alloc id of handle"/imm32
167 68/push 0/imm32
168 ff 6/subop/push 0/mod/indirect 1/rm32/ECX . . . . . .
169
170 e8/call check-ints-equal/disp32
171
172 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
173
174
175 68/push "F - test-new-failure: address of handle"/imm32
176 68/push 0/imm32
177 ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 .
178
179 e8/call check-ints-equal/disp32
180
181 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
182
183
184
185 68/push "F - test-new-failure: next alloc id"/imm32
186 68/push 0x34/imm32
187 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32
188
189 e8/call check-ints-equal/disp32
190
191 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
192
193
194 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
195
196 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
197 5d/pop-to-EBP
198 c3/return
199
200 lookup:
201
202 55/push-EBP
203 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
204
205 51/push-ECX
206 52/push-EDX
207
208 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 8/disp8 .
209
210 8b/copy 0/mod/indirect 1/rm32/ECX . . . 2/r32/EDX . .
211
212 8b/copy 1/mod/*+disp8 1/rm32/ECX . . . 0/r32/EAX 4/disp8 .
213
214 39/compare 0/mod/indirect 0/rm32/EAX . . . 2/r32/EDX . .
215 74/jump-if-equal $lookup:success/disp8
216
217
218
219
220
221 68/push "lookup failed"/imm32
222 68/push 2/imm32/stderr
223
224 e8/call _write/disp32
225
226 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
227
228 bb/copy-to-EBX 1/imm32/exit-status
229 b8/copy-to-EAX 1/imm32/exit
230 cd/syscall 0x80/imm8
231 $lookup:success:
232
233 05/add-to-EAX 4/imm32
234
235 5a/pop-to-EDX
236 59/pop-to-ECX
237
238 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
239 5d/pop-to-EBP
240 c3/return
241
242 test-lookup-success:
243
244 55/push-EBP
245 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
246
247
248 68/push 0/imm32/address
249 68/push 0/imm32/alloc-id
250 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
251
252 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 2/r32/EDX Heap/disp32 .
253
254
255 51/push-ECX
256 68/push 2/imm32/size
257 68/push Heap/imm32
258
259 e8/call new/disp32
260
261 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
262
263
264 51/push-ECX
265
266 e8/call lookup/disp32
267
268 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
269
270
271
272 68/push "F - test-lookup-success"/imm32
273 81 0/subop/add 3/mod/direct 2/rm32/EDX . . . . . 4/imm32
274 52/push-EDX
275 50/push-EAX
276
277 e8/call check-ints-equal/disp32
278
279 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
280
281
282 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
283
284 5a/pop-to-EDX
285 59/pop-to-ECX
286
287 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
288 5d/pop-to-EBP
289 c3/return
290
291 test-lookup-failure:
292
293 55/push-EBP
294 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
295
296 50/push-EAX
297 51/push-ECX
298 52/push-EDX
299
300 68/push 0/imm32/address
301 68/push 0/imm32/alloc-id
302 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
303
304 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Heap/disp32 .
305
306
307
308 51/push-ECX
309 68/push 2/imm32/size
310 68/push Heap/imm32
311
312 e8/call new/disp32
313
314 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
315
316 89/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Heap/disp32 .
317
318
319 68/push 0/imm32/address
320 68/push 0/imm32/alloc-id
321 89/copy 3/mod/direct 2/rm32/EDX . . . 4/r32/ESP . .
322
323
324 52/push-EDX
325 68/push 2/imm32/size
326 68/push Heap/imm32
327
328 e8/call new/disp32
329
330 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
331
332
333 68/push "F - test-lookup-failure"/imm32
334 ff 6/subop/push 1/mod/*+disp8 2/rm32/ECX . . . . 4/disp8 .
335 ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 .
336
337 e8/call check-ints-equal/disp32
338
339 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
340
341
342 51/push-ECX
343
344 e8/call lookup/disp32
345
346
347 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
348
349
350 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
351
352 5a/pop-to-EDX
353 59/pop-to-ECX
354 58/pop-to-EAX
355
356 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
357 5d/pop-to-EBP
358 c3/return
359
360 == data
361
362
363 Next-alloc-id:
364 01 00 00 00
365
366