Counting up vs counting down may have more about using pre- or post- unary construction, I mean ++x or --x are known as faster equivalents of x++ or x-- that explains more effective asm code of example with counting down.
Counting down has been used because many/most CPUs have instructions to loop until a counter has reached zero or to branch on zero flag. This avoids explicit comparisons at every iteration.
You can actually see that in the x86 assembly code examples in the slides: When counting up there is a cmpl instruction to perform the comparison with the end value before the conditional jump (jne). When counting down, the subl instruction will set the zero flag when the counter register reaches zero so that there no need for comparison and you can directly execute jne/jnz based on that flag. That also saves a register since you only need to keep track of the counter.
2 comments
[ 6.8 ms ] story [ 17.0 ms ] threadYou can actually see that in the x86 assembly code examples in the slides: When counting up there is a cmpl instruction to perform the comparison with the end value before the conditional jump (jne). When counting down, the subl instruction will set the zero flag when the counter register reaches zero so that there no need for comparison and you can directly execute jne/jnz based on that flag. That also saves a register since you only need to keep track of the counter.