Use this function to get the Max and Min value from series of data within integer array...
procedure MinMaxArray(const aArray:array of integer; out aMax,aMin:integer);
var
i,mi,ma:integer;
begin
ma := aArray[Low(aArray)];
mi := ma;
for i := Low(aArray) + 1 to High(aArray) do
begin
if (aArray[i] < mi) then mi:=aArray[i];
if (aArray[i] > ma) then ma:=aArray[i];
end;
aMax := ma;
aMin := mi;
end;
If you need more speed, a
BASM version could be used as follow...
procedure MinMaxArray(const aArray:array of integer;
out aMax,aMin:integer);
asm
push ebx
push esi
push edi
push ebp
mov ebx, ecx
mov ecx, [eax]
mov edi, ecx
inc edx
test edx, edx
jle @@Output
mov ebp, edx // ebp := edx mod 4
and ebp, 3
shr edx, 2 // edx := edx div 4
test edx, edx
jle @@RestMod4
@@LpMainBegin:
mov esi, [eax]
cmp esi, edi
db $0F,$4C,$FE { cmovl edi, esi }
cmp ecx, esi
db $0F,$4C,$CE { cmovl ecx, esi }
mov esi, [eax+4]
cmp esi, edi
db $0F,$4C,$FE { cmovl edi, esi }
cmp ecx, esi
db $0F,$4C,$CE { cmovl ecx, esi }
mov esi, [eax+8]
cmp esi, edi
db $0F,$4C,$FE { cmovl edi, esi }
cmp ecx, esi
db $0F,$4C,$CE { cmovl ecx, esi }
mov esi, [eax+12]
cmp esi, edi
db $0F,$4C,$FE { cmovl edi, esi }
cmp ecx, esi
db $0F,$4C,$CE { cmovl ecx, esi }
@@LpMainEnd:
add eax, 16
dec edx
jnz @@LpMainBegin
@@RestMod4:
test ebp, ebp
jle @@Output
@@LpRestBegin:
mov esi, [eax]
cmp esi, edi
db $0F,$4C,$FE { cmovl edi, esi }
cmp ecx, esi
db $0F,$4C,$CE { cmovl ecx, esi }
@@LpRestEnd:
add eax, 4
dec ebp
jnz @@LpRestBegin
@@Output:
pop ebp
mov eax, [ebp+$08]
mov [ebx], ecx // Output aMin //
mov [eax], edi // Output aMax //
pop edi
pop esi
pop ebx
end;
Code provided by Hubert Seidel
2 comments:
instead of using two if loops .. you can do it better by using elseif instead of second if
Post a Comment