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