https://github.com/akkartik/mu/blob/master/054string-equal.subx
1
2
3 == code
4
5
6
7
8 Entry:
9
10 e8/call run-tests/disp32
11
12 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32
13 b8/copy-to-eax 1/imm32/exit
14 cd/syscall 0x80/imm8
15
16 string-equal?:
17
18
19
20
21
22 55/push-ebp
23 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
24
25 51/push-ecx
26 56/push-esi
27 57/push-edi
28
29 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 .
30
31 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 .
32
33 8b/copy 0/mod/indirect 6/rm32/esi . . . 1/r32/ecx . .
34 $string-equal?:lengths:
35
36 39/compare 0/mod/indirect 7/rm32/edi . . . 1/r32/ecx . .
37 b8/copy-to-eax 0/imm32/false
38 75/jump-if-!= $string-equal?:end/disp8
39 $string-equal?:contents:
40
41
42 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
43 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
44
45 e8/call string-starts-with?/disp32
46
47 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
48 $string-equal?:end:
49
50 5f/pop-to-edi
51 5e/pop-to-esi
52 59/pop-to-ecx
53
54 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
55 5d/pop-to-ebp
56 c3/return
57
58 string-starts-with?:
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 55/push-ebp
80 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
81
82 51/push-ecx
83 52/push-edx
84 56/push-esi
85 57/push-edi
86
87 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 .
88
89 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 .
90
91 8b/copy 0/mod/indirect 7/rm32/edi . . . 1/r32/ecx . .
92 $string-starts-with?:lengths:
93
94 39/compare 0/mod/indirect 6/rm32/esi . . . 1/r32/ecx . .
95 7c/jump-if-< $string-starts-with?:false/disp8
96
97 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 4/imm32
98
99 81 0/subop/add 3/mod/direct 7/rm32/edi . . . . . 4/imm32
100
101 01/add 3/mod/direct 1/rm32/ecx . . . 7/r32/edi . .
102
103 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . .
104
105 31/xor 3/mod/direct 2/rm32/edx . . . 2/r32/edx . .
106 $string-starts-with?:loop:
107
108 39/compare 3/mod/direct 7/rm32/edi . . . 1/r32/ecx . .
109 73/jump-if-addr>= $string-starts-with?:true/disp8
110
111 8a/copy-byte 0/mod/indirect 6/rm32/esi . . . 0/r32/AL . .
112
113 8a/copy-byte 0/mod/indirect 7/rm32/edi . . . 2/r32/DL . .
114
115 39/compare 3/mod/direct 0/rm32/eax . . . 2/r32/edx . .
116 75/jump-if-!= $string-starts-with?:false/disp8
117
118 46/increment-esi
119
120 47/increment-edi
121 eb/jump $string-starts-with?:loop/disp8
122 $string-starts-with?:true:
123 b8/copy-to-eax 1/imm32
124 eb/jump $string-starts-with?:end/disp8
125 $string-starts-with?:false:
126 b8/copy-to-eax 0/imm32
127 $string-starts-with?:end:
128
129 5f/pop-to-edi
130 5e/pop-to-esi
131 5a/pop-to-edx
132 59/pop-to-ecx
133
134 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
135 5d/pop-to-ebp
136 c3/return
137
138
139
140 test-compare-empty-with-empty-string:
141
142
143 68/push ""/imm32
144 68/push ""/imm32
145
146 e8/call string-equal?/disp32
147
148 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
149
150
151 68/push "F - test-compare-empty-with-empty-string"/imm32
152 68/push 1/imm32/true
153 50/push-eax
154
155 e8/call check-ints-equal/disp32
156
157 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
158 c3/return
159
160 test-compare-empty-with-non-empty-string:
161
162
163 68/push "Abc"/imm32
164 68/push ""/imm32
165
166 e8/call string-equal?/disp32
167
168 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
169
170
171 68/push "F - test-compare-empty-with-non-empty-string"/imm32
172 68/push 0/imm32/false
173 50/push-eax
174
175 e8/call check-ints-equal/disp32
176
177 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
178 c3/return
179
180 test-compare-equal-strings:
181
182
183 68/push "Abc"/imm32
184 68/push "Abc"/imm32
185
186 e8/call string-equal?/disp32
187
188 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
189
190
191 68/push "F - test-compare-equal-strings"/imm32
192 68/push 1/imm32/true
193 50/push-eax
194
195 e8/call check-ints-equal/disp32
196
197 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
198 c3/return
199
200 test-compare-inequal-strings-equal-lengths:
201
202
203 68/push "Adc"/imm32
204 68/push "Abc"/imm32
205
206 e8/call string-equal?/disp32
207
208 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
209
210
211 68/push "F - test-compare-inequal-strings-equal-lengths"/imm32
212 68/push 0/imm32/false
213 50/push-eax
214
215 e8/call check-ints-equal/disp32
216
217 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
218 c3/return
219
220
221 check-strings-equal:
222
223 55/push-ebp
224 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
225
226 50/push-eax
227
228
229 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
230 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
231
232 e8/call string-equal?/disp32
233
234 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
235
236
237 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 .
238 68/push 1/imm32
239 50/push-eax
240
241 e8/call check-ints-equal/disp32
242
243 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
244 $check-strings-equal:end:
245
246 58/pop-to-eax
247
248 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
249 5d/pop-to-ebp
250 c3/return
251
252
253 test-check-strings-equal:
254
255
256 68/push "Abc"/imm32
257 68/push "Abc"/imm32
258
259 e8/call check-strings-equal/disp32
260
261 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
262 c3/return
263
264