.
: , . .
;
for (i=0; i<n; i++) s[i]=0;
for (i=1; i<n; i++)
for (j=0; j<i; j++)
if (x[j]>x[i]) s[j]+=1; else s[i]+=1;
;
for (i=0; i<n;i++)
y[s[i]]=x[i];
ideal
p386
model flat
extrn ExitProcess:proc
dataseg
fio1 db 'aaaaaaaa', 0
fio2 db 'bbbbbb', 0
fio3 db 'cccccccccccccccc', 0
fio4 db 'ddddddd', 0
fio5 db 'eeeeeeeeeeeeeeeeeeee', 0
struc data1
pfio dd ?
oc1 db ?
oc2 db ?
oc3 db ?
oc4 db ?
ends
gr1 data1 < offset fio1, 2, 3, 4, 5>, < offset fio2, 3,4,5,3>
data1 < offset fio3, 5, 5, 5, 5>, < offset fio4, 5,4,5,5>
data1 < offset fio5, 5, 4, 4, 4>
count dd 5
r data1 5 dup (?)
s dd 5 dup(0)
codeseg
begin:
;for (i=1; i<n; i++)
mov ecx, [count]
dec ecx
mov eax, 1
mov esi, offset gr1
add esi, 8
fori:
mov bl,0
add bl, [(data1 esi).oc1]
add bl, [(data1 esi).oc2]
add bl, [(data1 esi).oc3]
add bl, [(data1 esi).oc4]
; for (j=0; j<i; j++)
mov edx, 0
mov edi,offset gr1
forj:
cmp edx, eax
jge breakj
mov bh, 0
add bh, [(data1 edi).oc1]
add bh, [(data1 edi).oc2]
add bh, [(data1 edi).oc1]
add bh, [(data1 edi).oc1]
; if (x[j]>x[i]) s[j]+=1; else s[i]+=1;
cmp bh, bl
jge short mge
inc [s+edx*4]
jmp short nextj
mge:
inc [s+eax*4]
nextj:
inc edx
add edi, 8
jmp forj
;i++
breakj:
inc eax
add esi, 8
loop fori
;for (i=0; i<n;i++)
mov ecx, [count]
mov eax, 0
for2:
; y[s[i]]=x[i];
lea esi, [ gr1 + eax* 8]
mov ebx, [s+eax*4]
lea edi, [r+ebx*8]
mov edx, [(data1 esi).pfio]
mov [(data1 edi).pfio], edx
mov edx, [dword (data1 esi).oc1]
mov [dword (data1 edi).oc1], edx
;i++
inc eax
loop for2
call ExitProcess
end begin