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