This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Silly assembler optimizations

Hello!

I am trying to write a simple delay function in inline assembler, but no matter how hard I try, the complier always modifies my assembly code. My original BNE LOOP command was compiled into a strange combination of BEQ and B instructions:

    63: LOOP:
0x000069CC  E1A00000  NOP
    64:         SUBS       value,value,#0x00000001
0x000069D0  E2500001  SUBS      R0,R0,#0x00000001
0x000069D4  0A000000  BEQ       0x000069DC
    65:         BNE LOOP
    66: END:
    67: }
0x000069D8  EAFFFFFC  B         0x000069D0
    68: }
0x000069DC  E12FFF1E  BX        R14

And when I used the upper (compiler suggested) code as my source, the result was even more absurd:

    63: LOOP:
0x000069CC  E1A00000  NOP
    64:         SUBS       value,value,#0x00000001
0x000069D0  E2500001  SUBS      R0,R0,#0x00000001
0x000069D4  1A000000  BNE       0x000069DC
    65:         BEQ END
0x000069D8  EA000000  B         0x000069E0
    66:         B LOOP
0x000069DC  EAFFFFFB  B         0x000069D0
    67: END:
    68: }
0x000069E0  E1A00000  NOP
    69: }
0x000069E4  E12FFF1E  BX        R14

Can anyone tell me, why the compiler always tends to modify the user code?!? Can this "optimization" be turned off and is there any other way to avoid such cases in the future?

The code was compiled using ARM realview compiler v. 3.1.0.919.

Kind regards,

Matic

0