https://github.com/akkartik/mu/blob/master/subx/054string-equal.subx
1
2
3 == code
4
5
6
7
8
9
10
11 e8/call run-tests/disp32
12
13 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32
14 b8/copy-to-EAX 1/imm32/exit
15 cd/syscall 0x80/imm8
16
17 string-equal?:
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 55/push-EBP
41 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
42
43 51/push-ECX
44 52/push-EDX
45 53/push-EBX
46 56/push-ESI
47 57/push-EDI
48
49 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 8/disp8 .
50
51 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 0xc/disp8 .
52
53 8b/copy 0/mod/indirect 6/rm32/ESI . . . 2/r32/EDX . .
54 $string-equal?:lengths:
55
56 39/compare 0/mod/indirect 7/rm32/EDI . . . 2/r32/EDX . .
57 75/jump-if-not-equal $string-equal?:false/disp8
58
59 81 0/subop/add 3/mod/direct 6/rm32/ESI . . . . . 4/imm32
60
61 81 0/subop/add 3/mod/direct 7/rm32/EDI . . . . . 4/imm32
62
63 31/xor 3/mod/direct 1/rm32/ECX . . . 1/r32/ECX . .
64 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . .
65 31/xor 3/mod/direct 3/rm32/EBX . . . 3/r32/EBX . .
66 $string-equal?:loop:
67
68 39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . .
69 7d/jump-if-greater-or-equal $string-equal?:true/disp8
70
71 8a/copy-byte 0/mod/indirect 6/rm32/ESI . . . 0/r32/AL . .
72
73 8a/copy-byte 0/mod/indirect 7/rm32/EDI . . . 3/r32/BL . .
74
75 39/compare 3/mod/direct 0/rm32/EAX . . . 3/r32/EBX . .
76 75/jump-if-not-equal $string-equal?:false/disp8
77
78 41/inc-ECX
79
80 46/inc-ESI
81
82 47/inc-EDI
83 eb/jump $string-equal?:loop/disp8
84 $string-equal?:true:
85 b8/copy-to-EAX 1/imm32
86 eb/jump $string-equal?:end/disp8
87 $string-equal?:false:
88 b8/copy-to-EAX 0/imm32
89 $string-equal?:end:
90
91 5f/pop-to-EDI
92 5e/pop-to-ESI
93 5b/pop-to-EBX
94 5a/pop-to-EDX
95 59/pop-to-ECX
96
97 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
98 5d/pop-to-EBP
99 c3/return
100
101
102
103 test-compare-empty-with-empty-string:
104
105
106 68/push ""/imm32
107 68/push ""/imm32
108
109 e8/call string-equal?/disp32
110
111 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
112
113
114 68/push "F - test-compare-empty-with-empty-string"/imm32
115 68/push 1/imm32/true
116 50/push-EAX
117
118 e8/call check-ints-equal/disp32
119
120 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
121 c3/return
122
123 test-compare-empty-with-non-empty-string:
124
125
126 68/push "Abc"/imm32
127 68/push ""/imm32
128
129 e8/call string-equal?/disp32
130
131 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
132
133
134 68/push "F - test-compare-empty-with-non-empty-string"/imm32
135 68/push 0/imm32/false
136 50/push-EAX
137
138 e8/call check-ints-equal/disp32
139
140 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
141 c3/return
142
143 test-compare-equal-strings:
144
145
146 68/push "Abc"/imm32
147 68/push "Abc"/imm32
148
149 e8/call string-equal?/disp32
150
151 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
152
153
154 68/push "F - test-compare-equal-strings"/imm32
155 68/push 1/imm32/true
156 50/push-EAX
157
158 e8/call check-ints-equal/disp32
159
160 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
161 c3/return
162
163 test-compare-inequal-strings-equal-lengths:
164
165
166 68/push "Adc"/imm32
167 68/push "Abc"/imm32
168
169 e8/call string-equal?/disp32
170
171 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
172
173
174 68/push "F - test-compare-inequal-strings-equal-lengths"/imm32
175 68/push 0/imm32/false
176 50/push-EAX
177
178 e8/call check-ints-equal/disp32
179
180 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
181 c3/return
182
183