https://github.com/akkartik/mu/blob/master/examples/ex11.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 == code 0x09000000
18
19
20
21
22 Entry:
23 e8/call run-tests/disp32
24
25 89/copy 3/mod/direct 3/rm32/ebx . . . 0/r32/eax . .
26 b8/copy-to-eax 1/imm32/exit
27 cd/syscall 0x80/imm8
28
29
30
31 kernel-string-equal?:
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 55/push-ebp
55 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
56
57 51/push-ecx
58 52/push-edx
59 53/push-ebx
60 56/push-esi
61 57/push-edi
62
63 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 8/disp8 .
64
65 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 2/r32/edx 0xc/disp8 .
66 8b/copy 0/mod/indirect 2/rm32/edx . . . 2/r32/edx . .
67
68 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0xc/disp8 .
69 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 4/imm32
70
71 b9/copy-to-ecx 0/imm32/exit
72 b8/copy-to-eax 0/imm32
73 bb/copy-to-ebx 0/imm32
74 $kernel-string-equal?:loop:
75
76 39/compare 3/mod/direct 1/rm32/ecx . . . 2/r32/edx . .
77 7d/jump-if-greater-or-equal $kernel-string-equal?:break/disp8
78
79 8a/copy-byte 0/mod/indirect 7/rm32/edi . . . 0/r32/AL . .
80
81 8a/copy-byte 0/mod/indirect 6/rm32/esi . . . 3/r32/BL . .
82
83 3d/compare-eax-and 0/imm32
84 74/jump-if-equal $kernel-string-equal?:false/disp8
85
86 39/compare 3/mod/direct 0/rm32/eax . . . 3/r32/ebx . .
87 75/jump-if-not-equal $kernel-string-equal?:false/disp8
88
89 41/increment-ecx
90
91 47/increment-edi
92
93 46/increment-esi
94 eb/jump $kernel-string-equal?:loop/disp8
95 $kernel-string-equal?:break:
96
97 8a/copy-byte 0/mod/indirect 7/rm32/edi . . . 0/r32/AL . .
98 3d/compare-eax-and 0/imm32
99 75/jump-if-not-equal $kernel-string-equal?:false/disp8
100 $kernel-string-equal?:true:
101 b8/copy-to-eax 1/imm32
102 eb/jump $kernel-string-equal?:end/disp8
103 $kernel-string-equal?:false:
104 b8/copy-to-eax 0/imm32
105 $kernel-string-equal?:end:
106
107 5f/pop-to-edi
108 5e/pop-to-esi
109 5b/pop-to-ebx
110 5a/pop-to-edx
111 59/pop-to-ecx
112
113 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
114 5d/pop-to-ebp
115 c3/return
116
117
118
119 test-compare-null-kernel-string-with-empty-array:
120
121
122 68/push ""/imm32
123 68/push Null-kernel-string/imm32
124
125 e8/call kernel-string-equal?/disp32
126
127 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
128
129
130 68/push "F - test-compare-null-kernel-string-with-empty-array"/imm32
131 68/push 1/imm32/true
132 50/push-eax
133
134 e8/call check-ints-equal/disp32
135
136 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
137 c3/return
138
139 test-compare-null-kernel-string-with-non-empty-array:
140
141
142 68/push "Abc"/imm32
143 68/push Null-kernel-string/imm32
144
145 e8/call kernel-string-equal?/disp32
146
147 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
148
149
150 68/push "F - test-compare-null-kernel-string-with-non-empty-array"/imm32
151 68/push 0/imm32/false
152 50/push-eax
153
154 e8/call check-ints-equal/disp32
155
156 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
157 c3/return
158
159 test-compare-kernel-string-with-equal-array:
160
161
162 68/push "Abc"/imm32
163 68/push _test-Abc-kernel-string/imm32
164
165 e8/call kernel-string-equal?/disp32
166
167 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
168
169
170 68/push "F - test-compare-kernel-string-with-equal-array"/imm32
171 68/push 1/imm32/true
172 50/push-eax
173
174 e8/call check-ints-equal/disp32
175
176 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
177 c3/return
178
179 test-compare-kernel-string-with-inequal-array:
180
181
182 68/push "Adc"/imm32
183 68/push _test-Abc-kernel-string/imm32
184
185 e8/call kernel-string-equal?/disp32
186
187 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
188
189
190 68/push "F - test-compare-kernel-string-with-equal-array"/imm32
191 68/push 0/imm32/false
192 50/push-eax
193
194 e8/call check-ints-equal/disp32
195
196 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
197 c3/return
198
199 test-compare-kernel-string-with-empty-array:
200
201
202 68/push ""/imm32
203 68/push _test-Abc-kernel-string/imm32
204
205 e8/call kernel-string-equal?/disp32
206
207 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
208
209
210 68/push "F - test-compare-kernel-string-with-equal-array"/imm32
211 68/push 0/imm32/false
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 c3/return
218
219 test-compare-kernel-string-with-shorter-array:
220
221
222 68/push "Ab"/imm32
223 68/push _test-Abc-kernel-string/imm32
224
225 e8/call kernel-string-equal?/disp32
226
227 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
228
229
230 68/push "F - test-compare-kernel-string-with-shorter-array"/imm32
231 68/push 0/imm32/false
232 50/push-eax
233
234 e8/call check-ints-equal/disp32
235
236 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
237 c3/return
238
239 test-compare-kernel-string-with-longer-array:
240
241
242 68/push "Abcd"/imm32
243 68/push _test-Abc-kernel-string/imm32
244
245 e8/call kernel-string-equal?/disp32
246
247 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
248
249
250 68/push "F - test-compare-kernel-string-with-longer-array"/imm32
251 68/push 0/imm32/false
252 50/push-eax
253
254 e8/call check-ints-equal/disp32
255
256 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
257 c3/return
258
259
260
261
262 check-ints-equal:
263
264 55/push-ebp
265 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
266
267 51/push-ecx
268 53/push-ebx
269
270 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 8/disp8 .
271 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 3/r32/ebx 0xc/disp8 .
272
273 39/compare 3/mod/direct 0/rm32/eax . . . 3/r32/ebx . .
274 75/jump-if-unequal $check-ints-equal:else/disp8
275
276
277 68/push "."/imm32
278
279 e8/call write-stderr/disp32
280
281 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
282
283 eb/jump $check-ints-equal:end/disp8
284
285 $check-ints-equal:else:
286
287 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0x10/disp8 .
288
289
290 51/push-ecx
291
292 e8/call write-stderr/disp32
293
294 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
295
296
297 68/push Newline/imm32
298
299 e8/call write-stderr/disp32
300
301 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
302 $check-ints-equal:end:
303
304 5b/pop-to-ebx
305 59/pop-to-ecx
306
307 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
308 5d/pop-to-ebp
309 c3/return
310
311 write-stderr:
312
313 55/push-ebp
314 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
315
316 50/push-eax
317 51/push-ecx
318 52/push-edx
319 53/push-ebx
320
321
322 bb/copy-to-ebx 2/imm32
323
324 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 8/disp8 .
325 81 0/subop/add 3/mod/direct 1/rm32/ecx . . . . . 4/imm32
326
327 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 2/r32/edx 8/disp8 .
328 8b/copy 0/mod/indirect 2/rm32/edx . . . 2/r32/edx . .
329
330 b8/copy-to-eax 4/imm32/write
331 cd/syscall 0x80/imm8
332
333 5b/pop-to-ebx
334 5a/pop-to-edx
335 59/pop-to-ecx
336 58/pop-to-eax
337
338 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
339 5d/pop-to-ebp
340 c3/return
341
342 == data 0x0a000000
343
344 Newline:
345
346 1/imm32
347
348 0a/newline
349
350
351 Null-kernel-string:
352 00/null
353
354 _test-Abc-kernel-string:
355 41/A 62/b 63/c 00/null
356
357