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