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-string-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-string-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-string-equal:
211
212
213 68/push "Abc"/imm32
214 68/push "Abc"/imm32
215
216 e8/call check-string-equal/disp32
217
218 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
219
220
221 68/push "F - test-check-string-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