https://github.com/akkartik/mu/blob/main/linux/203stack.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-byte 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 e8/call syscall_exit/disp32
164
165
166 test-push:
167
168 55/push-ebp
169 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
170
171 68/push 0/imm32
172 68/push 0/imm32
173 68/push 8/imm32/size
174 68/push 0/imm32/top
175 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
176
177
178 68/push 0x42/imm32
179 51/push-ecx
180
181 e8/call push/disp32
182
183 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
184
185 58/pop-to-eax
186
187
188 68/push "F - test-push: top"/imm32
189 68/push 4/imm32
190 50/push-eax
191
192 e8/call check-ints-equal/disp32
193
194 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
195
196 58/pop-to-eax
197
198
199 68/push "F - test-push: size"/imm32
200 68/push 8/imm32
201 50/push-eax
202
203 e8/call check-ints-equal/disp32
204
205 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
206
207 58/pop-to-eax
208
209
210 68/push "F - test-push: data[0..3]"/imm32
211 68/push 0x42/imm32
212 50/push-eax
213
214 e8/call check-ints-equal/disp32
215
216 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
217
218 58/pop-to-eax
219
220
221 68/push "F - test-push: data[4..7]"/imm32
222 68/push 0/imm32
223 50/push-eax
224
225 e8/call check-ints-equal/disp32
226
227 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
228
229 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
230 5d/pop-to-ebp
231 c3/return
232
233
234 pop:
235
236 55/push-ebp
237 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
238
239 51/push-ecx
240 56/push-esi
241
242 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 .
243
244 81 7/subop/compare 0/mod/indirect 6/rm32/esi . . . . . 0/imm32
245 7e/jump-if-<= $pop:abort/disp8
246
247 81 5/subop/subtract 0/mod/direct 6/rm32/esi . . . . . 4/imm32
248
249 8b/copy 0/mod/indirect 6/rm32/esi . . . 1/r32/ecx . .
250 8b/copy 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/eax 8/disp8 .
251
252 c7 0/subop/copy 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/eax 8/disp8 0/imm32
253 $pop:end:
254
255 5e/pop-to-esi
256 59/pop-to-ecx
257
258 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
259 5d/pop-to-ebp
260 c3/return
261
262 $pop:abort:
263
264
265
266 68/push "error: pop: nothing left in stack&quo