# [送分题] 哪种循环速度快?解决方案(2)

www.MyException.Cn  网友分享于：2013-03-13  浏览：53次

for 汇编代码最少，也就快一些
------解决方案--------------------

------解决方案--------------------

------解决方案--------------------

------解决方案--------------------

------解决方案--------------------

------解决方案--------------------

--------

------解决方案--------------------

------解决方案--------------------
/----------------------------------------------------
// 1
for (i = 0; i < 256; i++)
{
//....
}
xor edx edx
mov [ebp-0x40],edx
...
inc dword ptr [ebp-0x40]
cmp [ebp-0x40],0x00000100
jl -0x39
//----------------------------------------------------
//2
i = 256;
while(i--)
{
//......
}
mov [ebp-0x40],0x00000100
jmp +0x2d
...
mov ecx,[ebp-0x40]
test ecx,ecx
jnz -0x38
//----------------------------------------------------
//3
i = 0;
do
{
//....
}while(i++ < 255);
xor eax eax
mov [ebp-0x40],eax
...
mov ecx,[ebp-0x40]
inc dword ptr [ebp-0x40]
cmp ecx,0x000000ff
jl -0x3b
//----------------------------------------------------
// 4
for (i = 0; i < 256; i++)
{
//....
}
mov [ebp-0x40],0x000000ff
...
dec dword ptr [ebp-0x40]
cmp dword ptr [ebp-0x40],0x00
jnl -0x36
//----------------------------------------------------

^_^

int i

register int i;

C++ Builder 6.0 pack2
complier-> code optimization-> none/speed

------解决方案--------------------

_________________________________________________________

------解决方案--------------------

// 4
for (i = 255; i > = 0; i++)
{
//....
}
mov [ebp-0x40],0x000000ff
...
dec dword ptr [ebp-0x40]
cmp dword ptr [ebp-0x40],0x00
jnl -0x36
------解决方案--------------------

------解决方案--------------------

------解决方案--------------------

------解决方案--------------------

------解决方案--------------------

------解决方案--------------------