74 lines
1.1 KiB
NASM
74 lines
1.1 KiB
NASM
%include "rw32-2022.inc"
|
|
|
|
segment .data
|
|
|
|
arr1 dt 1.6, -4.1, 1.1, -5.0
|
|
|
|
segment .text
|
|
|
|
;cdecl float * getSorted(const long double *pArr, unsigned int N)
|
|
|
|
getSorted:
|
|
enter 0,0
|
|
|
|
mov eax,[ebp+12]
|
|
shl eax,2
|
|
push eax
|
|
CEXTERN malloc
|
|
call malloc
|
|
add esp,4
|
|
|
|
mov ecx,[ebp+12]
|
|
mov esi,[ebp+8]
|
|
mov edi,eax
|
|
.cpy:
|
|
fld tword [esi]
|
|
add esi,10
|
|
fstp dword [edi]
|
|
add edi,4
|
|
loop .cpy
|
|
|
|
;for(unsigned int i = 0; i < N ; i++)
|
|
; for(unsigned int j = i + 1; j < N; j++)
|
|
; if (newArr[i] > newArr[j]) SWAP newArr[i],newArr[j]
|
|
|
|
xor esi,esi ; esi = i = 0
|
|
.for1:
|
|
cmp esi,[ebp+12]
|
|
jae .end_for1
|
|
lea edi,[esi+1] ; edi = j = i + 1
|
|
.for2:
|
|
cmp edi,[ebp+12]
|
|
jae .end_for2
|
|
|
|
fld dword [eax + esi*4]
|
|
fld dword [eax + edi*4]
|
|
fcomi
|
|
jbe .no_swap
|
|
fst dword [eax + esi*4]
|
|
fxch
|
|
fst dword [eax + edi*4]
|
|
.no_swap:
|
|
fcompp
|
|
inc edi
|
|
jmp .for2
|
|
.end_for2:
|
|
|
|
inc esi
|
|
jmp .for1
|
|
.end_for1:
|
|
|
|
leave
|
|
ret
|
|
|
|
CMAIN:
|
|
|
|
push 4
|
|
push arr1
|
|
call getSorted
|
|
add esp,8
|
|
|
|
mov esi,eax
|
|
mov ecx,4
|
|
call WriteArrayFloat
|
|
ret |