能力值:
( LV9,RANK:170 )
2 楼
Var
name:string;
a:integer;
begin
name:=edit1.text;
a:=0;
asm
PUSH ESI
lea ESI,name
XOR EAX,EAX
XOR EBX,EBX
@1:
MOV AL,[ESI]
TEST AL,AL
JE @2
ADD EBX,EAX
INC ESI
JMP @1
@2:
MOV a,EBX
POP ESI
end;
edit2.text:=inttostr(a);
end;
end.
能力值:
( LV12,RANK:650 )
3 楼
可以编译的 不要用ebx:
An asm statement must preserve the EDI, ESI, ESP, EBP, and EBX registers, but can freely modify the EAX, ECX, and EDX registers.
另外,不要用string,要用pchar,除非你用shortstring
能力值:
( LV13,RANK:1370 )
4 楼
最初由 firstrose 发布 不要用ebx
谢谢firstrose,正解,原来是这样.下面的编译可以通过:
Var
name:STRING;
a:integer;
begin
name:=edit1.text;
a:=0;
asm
MOV ESI,DWORD PTR SS:[name]
PUSH ESI
XOR EAX,EAX
XOR EDI,EDI
@1:
MOV AL,BYTE PTR DS:[ESI]
TEST AL,AL
JE @2
ADD EDI,EAX
INC ESI
JMP @1
@2:
MOV a,EDI
POP ESI
end;
edit2.text:=inttostr(a);
end;
能力值:
( LV2,RANK:10 )
5 楼
谢谢firstrose,正解,原来是这样.下面的编译可以通过:
Var
name:STRING;
a:integer;
begin
name:=edit1.text;
a:=0;
asm
MOV ESI,DWORD PTR SS:[name]
PUSH ESI
XOR EAX,EAX
XOR EDI,EDI
我服了楼上的了, push esi 放在设置esi 之后, 你没看人家给你的回复
能力值:
( LV13,RANK:1370 )
6 楼
进一步完善一下:加入对话框提示.
procedure TForm1.Button1Click(Sender: TObject);
Var
name:string;
a:integer;
title:string;
text:string;
begin
title:='提示';
text:='请输入用户名';
name:=edit1.text;
asm
PUSH ESI
MOV ESI,DWORD PTR SS:[name]
JE @3
XOR EAX,EAX
XOR EDI,EDI
@1:
MOV AL,BYTE PTR DS:[ESI]
TEST AL,AL
JE @2
ADD EDI,EAX
INC ESI
JMP @1
@2:
MOV a,EDI
POP ESI
JMP @4
@3:
push 0
MOV EAX,DWORD PTR SS:[title]
PUSH EAX
MOV EAX,DWORD PTR SS:[text]
PUSH EAX
PUSH 0
CALL MessageBox
@4:
end;
edit2.text:=inttostr(a);
end;
end.
能力值:
( LV8,RANK:130 )
7 楼
随便改一下看看
MOV EDX,DWORD PTR SS:[name] ;U-P
TEST EDX,EDX ;V-P
JZ @3 ;U-P
XOR EAX,EAX ;V-P
XOR ECX,ECX ;U-SINGLE
@1:
MOV AL,BYTE PTR DS:[EDX] ;U-P (From round 2)
INC EDX ;V-P (Write after read without ACL)
ADD ECX,EAX ;U-P
TEST EAX,EAX ;V-P
JNZ @1 ;U-NP
@2:
MOV [a],ECX ;U-P
JMP @4 ;V-P
@3:
MOV EAX,DWORD PTR SS:[title] ;U-P
MOV ECX,DWORD PTR SS:[text] ;V-P
PUSH EDX ;S-P
PUSH EAX ;S-P
PUSH ECX ;S-P
PUSH EDX ;S-P
CALL MessageBox ;U-NP
@4:
能力值:
( LV13,RANK:1370 )
8 楼
另外,想知道下面的形式能不能直接用于内联汇编:
call @1
@1:
...
retn