1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
.486
.model flat
extrn __fltused:near
extrn __ftol:near
_DATA segment
public _in
align 4
_in label byte
dd 10
dd 32
dd -1
dd 567
dd 3
dd 18
dd 1
dd -51
dd 789
dd 0
public _main
_DATA ends
_TEXT segment
_main:
push ebx
push esi
push edi
push ebp
mov ebp,esp
sub esp,4
push 10
lea edi,(_in)
push edi
call _sort
add esp,8
mov dword ptr (-4)[ebp],0
jmp L5
L2:
mov edi,dword ptr (-4)[ebp]
mov edi,dword ptr (_in)[edi*4]
push edi
call _putd
add esp,4
push 10
call _putchar
add esp,4
L3:
inc dword ptr (-4)[ebp]
L5:
mov edi,dword ptr (-4)[ebp]
cmp edi,10
jb L2
mov eax,0
L1:
mov esp,ebp
pop ebp
pop edi
pop esi
pop ebx
ret
public _putd
_putd:
push ebx
push esi
push edi
push ebp
mov ebp,esp
cmp dword ptr (20)[ebp],0
jge L7
push 45
call _putchar
add esp,4
neg dword ptr (20)[ebp]
L7:
mov eax,dword ptr (20)[ebp]
mov edi,10
cdq
idiv edi
cmp eax,0
je L9
mov eax,dword ptr (20)[ebp]
mov edi,10
cdq
idiv edi
push eax
call _putd
add esp,4
L9:
mov eax,dword ptr (20)[ebp]
mov edi,10
cdq
idiv edi
lea edi,(48)[edx]
push edi
call _putchar
add esp,4
mov eax,0
L6:
mov esp,ebp
pop ebp
pop edi
pop esi
pop ebx
ret
public _sort
_sort:
push ebx
push esi
push edi
push ebp
mov ebp,esp
mov edi,dword ptr (24)[ebp]
sub edi,1
mov dword ptr (24)[ebp],edi
push edi
push 0
mov edi,dword ptr (20)[ebp]
mov dword ptr (_xx),edi
push edi
call _quick
add esp,12
mov eax,0
L11:
mov esp,ebp
pop ebp
pop edi
pop esi
pop ebx
ret
public _quick
_quick:
push ebx
push esi
push edi
push ebp
mov ebp,esp
sub esp,4
mov edi,dword ptr (28)[ebp]
cmp dword ptr (24)[ebp],edi
jl L13
jmp L12
L13:
mov edi,dword ptr (28)[ebp]
push edi
mov edi,dword ptr (24)[ebp]
push edi
mov edi,dword ptr (20)[ebp]
push edi
call _partition
add esp,12
mov dword ptr (-4)[ebp],eax
mov edi,dword ptr (-4)[ebp]
sub edi,1
push edi
mov edi,dword ptr (24)[ebp]
push edi
mov edi,dword ptr (20)[ebp]
push edi
call _quick
add esp,12
mov edi,dword ptr (28)[ebp]
push edi
mov edi,dword ptr (-4)[ebp]
lea edi,(1)[edi]
push edi
mov edi,dword ptr (20)[ebp]
push edi
call _quick
add esp,12
mov eax,0
L12:
mov esp,ebp
pop ebp
pop edi
pop esi
pop ebx
ret
public _partition
_partition:
push ebx
push esi
push edi
push ebp
mov ebp,esp
sub esp,8
inc dword ptr (28)[ebp]
mov edi,dword ptr (24)[ebp]
mov dword ptr (-8)[ebp],edi
mov edi,dword ptr (-8)[ebp]
mov esi,dword ptr (20)[ebp]
mov edi,dword ptr [esi][edi*4]
mov dword ptr (-4)[ebp],edi
jmp L17
L16:
inc dword ptr (24)[ebp]
jmp L20
L19:
inc dword ptr (24)[ebp]
L20:
mov edi,dword ptr (24)[ebp]
mov esi,dword ptr (20)[ebp]
mov ebx,dword ptr (-4)[ebp]
cmp dword ptr [esi][edi*4],ebx
jl L19
dec dword ptr (28)[ebp]
jmp L23
L22:
dec dword ptr (28)[ebp]
L23:
mov edi,dword ptr (28)[ebp]
mov esi,dword ptr (20)[ebp]
mov ebx,dword ptr (-4)[ebp]
cmp dword ptr [esi][edi*4],ebx
jg L22
mov edi,dword ptr (28)[ebp]
cmp dword ptr (24)[ebp],edi
jge L25
mov edi,dword ptr (20)[ebp]
mov esi,dword ptr (28)[ebp]
lea esi,[edi][esi*4]
push esi
mov esi,dword ptr (24)[ebp]
lea edi,[edi][esi*4]
push edi
call _exchange
add esp,8
L25:
L17:
mov edi,dword ptr (28)[ebp]
cmp dword ptr (24)[ebp],edi
jl L16
mov edi,dword ptr (20)[ebp]
mov esi,dword ptr (28)[ebp]
lea esi,[edi][esi*4]
push esi
mov esi,dword ptr (-8)[ebp]
lea edi,[edi][esi*4]
push edi
call _exchange
add esp,8
mov eax,dword ptr (28)[ebp]
L15:
mov esp,ebp
pop ebp
pop edi
pop esi
pop ebx
ret
public _exchange
_exchange:
push ebx
push esi
push edi
push ebp
mov ebp,esp
sub esp,4
mov edi,dword ptr (_xx)
mov esi,4
mov ebx,dword ptr (24)[ebp]
sub ebx,edi
mov eax,ebx
cdq
idiv esi
push eax
mov ebx,dword ptr (20)[ebp]
sub ebx,edi
mov eax,ebx
cdq
idiv esi
push eax
lea edi,(L28)
push edi
call _printf
add esp,12
mov edi,dword ptr (20)[ebp]
mov esi,dword ptr [edi]
mov dword ptr (-4)[ebp],esi
mov esi,dword ptr (24)[ebp]
mov esi,dword ptr [esi]
mov dword ptr [edi],esi
mov edi,dword ptr (24)[ebp]
mov esi,dword ptr (-4)[ebp]
mov dword ptr [edi],esi
mov eax,0
L27:
mov esp,ebp
pop ebp
pop edi
pop esi
pop ebx
ret
_TEXT ends
extrn _printf:near
_TEXT segment
_TEXT ends
extrn _putchar:near
_TEXT segment
_TEXT ends
_DATA segment
public _xx
align 4
_xx label byte
db 4 dup (0)
_DATA ends
_TEXT segment
align 1
L28 label byte
db 101
db 120
db 99
db 104
db 97
db 110
db 103
db 101
db 40
db 37
db 100
db 44
db 37
db 100
db 41
db 10
db 0
_TEXT ends
end
|