, , , , , . , , .
, x, x - , x. , , , . ...
int i;
for (i = 0; i < x; i++)
doStuff(array[i]);
, -
int i;
for (i = x-1; i != 0; i--)
{
doStuff(array[i]);
}
doStuff(array[0]);
, , .
MaR . , doStuff() int:
int i = x;
while (i != 0)
{
--i;
printf("%d\n",doStuff(array[i]));
}
, , .
. , ( ), , , , .
(x < y), :
(x!= 0), :
- test x to set the z flag branch
- based on z flag value
You can skip the subtraction command for each iteration.
There are architectures where you can have a subtraction command that sets flags based on the result of the subtraction, but I'm sure x86 is not one of them, so most of us do not use compilers that have access to such a machine instruction.
source
share