to:kinneng,我是表示这么一个算法的意思,因为在循环内入栈出栈速度肯定不快。我测试了一下如下结果:
使用test 7,循环100000000次,耗时 581毫秒,代码如下:
var aa,bb,i,j: integer;
begin
aa:= 3;
bb:= 5;
j:= GetTickCount;
for i:= 0 to 100000000 do
test7(aa,bb);
showmessage(inttostr(GetTickCount-j));
showmessage(inttostr(aa)+ inttostr(bb));
然后修改为如下代码,运行时间为 190毫秒:
procedure TForm1.Button1Click(Sender: TObject);
var aa,bb,i,j: integer;
label tt;
begin
aa:= 3;
bb:= 5;
j:= GetTickCount;
asm
push ebx
mov eax,aa
mov edx,bb
mov ebx,$05F5E101
tt:mov ecx,eax
mov eax,edx
mov edx,ecx
dec ebx
jnz tt
mov aa,eax
mov bb,edx
pop ebx
end;
showmessage(inttostr(GetTickCount-j));
showmessage(inttostr(aa)+ inttostr(bb));
end;