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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 55/push-ebp
38 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
39
40 51/push-ecx
41 52/push-edx
42 56/push-esi
43 57/push-edi
44
45 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 .
46
47 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 .
48
49 8b/copy 0/mod/indirect 6/rm32/esi . . . 1/r32/ecx . .
50 $string-equal?:lengths:
51
52 39/compare 0/mod/indirect 7/rm32/edi . . . 1/r32/ecx . .
53 75/jump-if-not-equal $string-equal?:false/disp8
54
55 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 4/imm32
56
57 01/add 3/mod/direct 1/rm32/ecx . . . 6/r32/esi . .
58
59 81 0/subop/add 3/mod/direct 7/rm32/edi . . . . . 4/imm32
60
61 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . .
62 31/xor 3/mod/direct 2/rm32/edx . . . 2/r32/edx . .
63 $string-equal?:loop:
64
65 39/compare 3/mod/direct 6/rm32/esi . . . 1/r32/ecx . .
66 73/jump-if-greater-or-equal-unsigned $string-equal?:true/disp8
67
68 8a/copy-byte 0/mod/indirect 6/rm32/esi . . . 0/r32/AL . .
69
70 8a/copy-byte 0/mod/indirect 7/rm32/edi . . . 2/r32/DL . .
71
72 39/compare 3/mod/direct 0/rm32/eax . . . 2/r32/edx . .
73 75/jump-if-not-equal $string-equal?:false/disp8
74
75 46/increment-esi
76
77 47/increment-edi
78 eb/jump $string-equal?:loop/disp8
79 $string-equal?:true:
80 b8/copy-to-eax 1/imm32
81 eb/jump $string-equal?:end/disp8
82 $string-equal?:false:
83 b8/copy-to-eax 0/imm32
84 $string-equal?:end:
85
86 5f/pop-to-edi
87 5e/pop-to-esi
88 5a/pop-to-edx
89 59/pop-to-ecx
90
91 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
92 5d/pop-to-ebp
93 c3/return
94
95
96
97 test-compare-empty-with-empty-string:
98
99
100 68/push ""/imm32
101 68/push ""/imm32
102
103 e8/call string-equal?/disp32
104
105 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
106
107
108 68/push "F - test-compare-empty-with-empty-string"/imm32
109 68/push 1/imm32/true
110 50/push-eax
111
112 e8/call check-ints-equal/disp32
113
114 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
115 c3/return
116
117 test-compare-empty-with-non-empty-string:
118
119
120 68/push "Abc"/imm32
121 68/push ""/imm32
122
123 e8/call string-equal?/disp32
124
125 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
126
127
128 68/push "F - test-compare-empty-with-non-empty-string"/imm32
129 68/push 0/imm32/false
130 50/push-eax
131
132 e8/call check-ints-equal/disp32
133
134 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
135 c3/return
136
137 test-compare-equal-strings:
138
139
140 68/push "Abc"/imm32
141 68/push "Abc"/imm32
142
143 e8/call string-equal?/disp32
144
145 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
146
147
148 68/push "F - test-compare-equal-strings"/imm32
149 68/push 1/imm32/true
150 50/push-eax
151
152 e8/call check-ints-equal/disp32
153
154 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
155 c3/return
156
157 test-compare-inequal-strings-equal-lengths:
158
159
160 68/push "Adc"/imm32
161 68/push "Abc"/imm32
162
163 e8/call string-equal?/disp32
164
165 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
166
167
168 68/push "F - test-compare-inequal-strings-equal-lengths"/imm32
169 68/push 0/imm32/false
170 50/push-eax
171
172 e8/call check-ints-equal/disp32
173
174 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
175 c3/return
176
177
178 check-strings-equal:
179
180 55/push-ebp
181 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
182
183 50/push-eax
184
185
186 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
187 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
188
189 e8/call string-equal?/disp32
190
191 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
192
193
194 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 .
195 68/push 1/imm32
196 50/push-eax
197
198 e8/call check-ints-equal/disp32
199
200 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
201 $check-strings-equal:end:
202
203 58/pop-to-eax
204
205 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
206 5d/pop-to-ebp
207 c3/return
208
209
210 test-check-strings-equal:
211
212
213 68/push "Abc"/imm32
214 68/push "Abc"/imm32
215
216 e8/call check-strings-equal/disp32
217
218 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
219
220
221 68/push "F - test-check-strings-equal"/imm32
222 68/push 0/imm32/false
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 c3/return
229
230