I agree that looks odd at first, but I don't think the compiler is wrong.
The loop you've provided doesn't do anything, so the optimizer is free to
modify it -- I would have expected the loop to be completely removed. If
you put something in the loop body, such as " asm("nop");", then the
compiler's output becomes 25 nop instructions, followed by incrementing the
loop counter by 25 and comparing the result to 100. This does cause the
contents of the loop to be executed 100 times.
In the code you've provided, the compiler unrolled the loop by executing its
contents 25 times before comparing the counter to 100. This means the code
only tests for completion of the loop 4 times, which speeding execution,
while using one quarter of the code space of a completely unrolled loop.
Since the loop doesn't do anything, the unrolled loop doesn't do anything
either.
If you're looking for a delay loop, put a nop inside the loop, or make the
loop index a volatile variable.
I hope this helps,
Neil
On 5/24/07, Robert Kong Win Chang <[email protected]> wrote:
The code below was compiled using a pre-compiled version of msp430-gcc(
3.2.3) for WinXP under cygwin:
msp430-gcc –mmcu=msp430x1232 –O2 –Wall –g loop.c –o loop
msp430-objdump –dSt loop > loop.lst
Instead of adding one to r15, 25 is being added.
void Loop(void)
{
Uint16 t;
for(t = 0; t < 100; t++){
e040: 0f 43 clr r15 ;
e042: 3f 50 19 00 add #25, r15 ;#0x0019
e046: 3f 90 64 00 cmp #100, r15 ;#0x0064
e04a: fb 2b jnc $-8 ;abs 0xe042
;
}
}
e04c: 30 41 ret