program-with-loop
Source:
samek-embedded
See also:
General considerations for non-linear control flow
Code and instructions
Code
| |
Disassembly

Comparison
| Original structure | Optimised structure |
|---|---|
![]() | ![]() |
- In the compiled code, the execution of the while loop is different than that given by the code.
- However, the effect of the loop on the calculation remains the same.
- The compiler proposes this order of instructions for increased efficiency, e.g. the
BLT.Ninstruction steps back to++counterinstead of forwards, which allows thePCregister to naturally increment without having to use another branch instruction.
Compare
| Before | ![]() |
| After | ![]() |
CMP modifies the APSR (Application Program Status Register)
N bit (negative) is set, because R0 - #10 is negative



