1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
unit USDXStrUtils;
interface
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
uses ModiSDK;
//function StrToAChar(Str: String): AChar;
function CreateStr(Str: PChar): PChar;
procedure FreeStr(Str: PChar);
implementation
{$IFDEF FPC}
{$ASMMODE Intel}
{$ENDIF}
{function StrToAChar(Str: String): AChar;
var
L, I: Integer;
begin
L := Length(Str);
For I := 0 to L-1 do
AChar[I] := Str[I+1];
For I := L to 254 do
AChar[I] := #0;
end; }
function StrCopy(Dest, Source: PChar): PChar; assembler;
asm
PUSH EDI
PUSH ESI
MOV ESI,EAX
MOV EDI,EDX
MOV ECX,0FFFFFFFFH
XOR AL,AL
REPNE SCASB
NOT ECX
MOV EDI,ESI
MOV ESI,EDX
MOV EDX,ECX
MOV EAX,EDI
SHR ECX,2
REP MOVSD
MOV ECX,EDX
AND ECX,3
REP MOVSB
POP ESI
POP EDI
end;
function StrLen(Str: PChar): Cardinal; assembler;
asm
MOV EDX,EDI
MOV EDI,EAX
MOV ECX,0FFFFFFFFH
XOR AL,AL
REPNE SCASB
MOV EAX,0FFFFFFFEH
SUB EAX,ECX
MOV EDI,EDX
end;
function CreateStr(Str: PChar): PChar;
begin
GetMem(Result, StrLen(Str) + 1);
StrCopy(Result, Str);
end;
procedure FreeStr(Str: PChar);
begin
FreeMem(Str);
end;
end.
|