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
63 31/xor 3/mod/direct 2/rm32/edx . . . 2/r32/edx . .
64 $string-equal?:loop:
65
66 39/compare 3/mod/direct 6/rm32/esi . . . 1/r32/ecx . .
67 73/jump-if-greater-or-equal-unsigned $string-equal?:true/disp8
68
69 8a/copy-byte 0/mod/indirect 6/rm32/esi . . . 0/r32/AL . .
70
71 8a/copy-byte 0/mod/indirect 7/rm32/edi . . . 2/r32/DL . .
72
73 39/compare 3/mod/direct 0/rm32/eax . . . 2/r32/edx . .
74 75/jump-if-not-equal $string-equal?:false/disp8
75
76 46/increment-esi
77
78 47/increment-edi
79 eb/jump $string-equal?:loop/disp8
80 $string-equal?:true:
81 b8/copy-to-eax 1/imm32
82 eb/jump $string-equal?:end/disp8
83 $string-equal?:false:
84 b8/copy-to-eax 0/imm32
85 $string-equal?:end:
86
87 5f/pop-to-edi
88 5e/pop-to-esi
89 5a/pop-to-edx
90 59/pop-to-ecx
91
92 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
93 5d/pop-to-ebp
94 c3/return
95
96
97
98 test-compare-empty-with-empty-string:
99
100
101 68/push ""/imm32
102 68/push ""/imm32
103
104 e8/call string-equal?/disp32
105
106 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
107
108
109 68/push "F - test-compare-empty-with-empty-string"/imm32
110 68/push 1/imm32/true
111 50/push-eax
112
113 e8/call check-ints-equal/disp32
114
115 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
116 c3/return
117
118 test-compare-empty-with-non-empty-string:
119
120
121 68/push "Abc"/imm32
122 68/push ""/imm32
123
124 e8/call 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-empty-with-non-empty-string"/imm32
130 68/push 0/imm32/false
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-equal-strings:
139
140
141 68/push "Abc"/imm32
142 68/push "Abc"/imm32
143
144 e8/call 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-equal-strings"/imm32
150 68/push 1/imm32/true
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-inequal-strings-equal-lengths:
159
160
161 68/push "Adc"/imm32
162 68/push "Abc"/imm32
163
164 e8/call 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-inequal-strings-equal-lengths"/imm32
170 68/push 0/imm32/false
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
179 check-strings-equal:
180
181 55/push-ebp
182 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
183
184 50/push-eax
185
186
187 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
188 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
189
190 e8/call string-equal?/disp32
191
192 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
193
194
195 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 .
196 68/push 1/imm32
197 50/push-eax
198
199 e8/call check-ints-equal/disp32
200
201 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
202 $check-strings-equal:end:
203
204 58/pop-to-eax
205
206 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
207 5d/pop-to-ebp
208 c3/return
209
210
211 test-check-strings-equal:
212
213
214 68/push "Abc"/imm32
215 68/push "Abc"/imm32
216
217 e8/call check-strings-equal/disp32
218
219 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
220 c3/return
221
222