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