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