Re: String Functions



Hi John,

> Yes, but maybe the inner loop could be replaced by some ASM
> code (something like Andreas Hausladen's SmallDivMod
> routine) to make it even faster. --JohnH

I had modified your function using my DivMod10.

--
regards
Aleksandr


function DivMod10_Sha(c: cardinal; var d: cardinal): cardinal; overload;
asm
push edx
mov edx, $CCCCCCCD
mov ecx, eax
mul edx
xor ecx, edx
mov eax, edx
and ecx, 1
and eax, 7
jnz @nzero
test ecx, ecx
jz @zero
@nzero:
sub eax, ecx
add eax, 2
@zero:
pop ecx
shr edx, 3
mov [ecx], edx
end;

function DivMod10_Sha(var Value: cardinal): cardinal; overload;
asm
push eax
mov eax, [eax]
mov edx, $CCCCCCCD
mov ecx, eax
mul edx
xor ecx, edx
mov eax, edx
and ecx, 1
and eax, 7
jnz @nzero
test ecx, ecx
jz @zero
@nzero:
sub eax, ecx
add eax, 2
@zero:
pop ecx
shr edx, 3
mov [ecx], edx
end;

function IntToStr_Sha(Value: integer): string;
var
Buffer: array [0..11] of char;
Negative, Blank: integer;
begin;
Negative:=0;
if Value<0 then begin;
Negative:=-1;
Value:=-Value;
end;
Blank:=High(Buffer);
repeat;
Buffer[Blank]:=char(ord('0')+DivMod10_Sha(cardinal(Value)));
dec(Blank);
until Value=0;
Buffer[Blank]:='-';
Blank:=Blank+Negative;
SetString(Result,pchar(@Buffer[Blank+1]),High(Buffer)-Blank);
end;



.



Relevant Pages