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