...einen String sehr schnell gemäß ausgewählten Trennzeichen teilen (2)?
Autor: Juhani Suhonen
// after optimizations with delphi it comes a
// time for some assembler; also the memory
// management (slow result allocation) has been
// taken care of...
// note : You MUST have the following global
// variables :
// var
// Splitresult : Array[0..1023] of Char;
// P_SplitResArray : Pointer;
// then on form1.create assign Pointer :
// P_SplitResArray := @SplitResult;
// variable Splitresult will contain
// the result after procedure has been completed
procedure split5(const input: string; schar: Char; s: Byte); register;
asm
PUSH ECX
PUSH EAX //registers :
PUSH EDX //EAX = input
PUSH EDI //DH = s
TEST EAX, EAX //if input = '' then
JZ @NoWords // goto @NoInput
@WeHaveIt:MOV DH, CL //DL = schar
MOV EDI, EAX //EDI := Addr(input);
MOV ECX, [EDI-4] //ECX := length(input);
@GoGo: MOV AL, DL //AL := Schar;
CMP DH, 2 //IF DH = 2 then
JE @StartCo // goto @StartCo
MOV AH, 2 //AH (upper 8 bits of AX) will be our separator counter initial value is 2, max 256
@Lop: INC AH //AH := AH + 1
REPNE SCASB //while (EDI^<>AL) and (ECX>0) begin INC EDI; DEC ECX; end;
CMP AH, DH //if AH < DH then
JB @Lop // goto @Lop
TEST ECX, ECX //IF ECX > 0 then
JG @StartCo // goto @StartCp
@NoWords: MOV EDI,[P_SplitResArray] //result :=
MOV BYTE PTR [EDI], $0 // ''
JMP @TotalEnd
@StartCo: PUSH ESI
MOV ESI, EDI
MOV EDI, [P_SplitResArray]
@CopyLoop:MOV AH, BYTE PTR[ESI+0] //32 bit aligned loop.. hopefully :)
CMP AH, DL //1. test, 8 bits
JE @Endword
MOV BYTE PTR [EDI+0], AH
INC EDI
MOV AH, BYTE PTR[ESI+1]
CMP AH, DL //2. test, 8 bits -> 16 bits..
JE @Endword
MOV BYTE PTR [EDI+0], AH
INC EDI
MOV AH, BYTE PTR[ESI+2]
CMP AH, DL //3. test, 8 bits -> 24 bits..
JE @Endword
MOV BYTE PTR [EDI+0], AH
INC EDI
MOV AH, BYTE PTR[ESI+3]
CMP AH, DL //4. test, 8 bits -> 32 bits..
JE @Endword
MOV BYTE PTR [EDI+0], AH
INC EDI
ADD ESI, 4
SUB ECX, 4
CMP ECX, 0
JG @Copyloop
@EndWord: MOV BYTE PTR [EDI], $0 //lisää nolla
POP ESI
@TotalEnd:POP EDI
POP EDX
POP EAX
POP ECX
@Final: RET
printed from
www.swissdelphicenter.ch
developers knowledge base