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

Why does compiler produce different code for 46: Disp=DispData8; C:0x02DD 908082 MOV DPTR,#Disp(0x8082) C:0x02E0 7438 MOV A,#0x38 C:0x02E2 F0 MOVX @DPTR,A 47: wait(22); C:0x02E3 7F16

Compiler produces different code for same line

Parents
  • I set the optimize to 0, problem went away

    So there wasn't any actual problem in the first place!

    The compiler was just doing a perfectly valid optimisation - omitting an unnecessary re-load of the DPTR - exactly as any assembler programmer would have done if writing this manually!

Reply
  • I set the optimize to 0, problem went away

    So there wasn't any actual problem in the first place!

    The compiler was just doing a perfectly valid optimisation - omitting an unnecessary re-load of the DPTR - exactly as any assembler programmer would have done if writing this manually!

Children
  • So there wasn't any actual problem in the first place!

    There was: the source code was implicitly making an incorrect assumption, causing incorrect behaviour.   And that problem remains unsolved.

    On top of that, there are probably quite a number of even worse problems of similar kinds lurking in that source base.

    The morale: if you observe a problem goes away by changing optimization levels, the actual problem is pretty much guaranteed not to be with the compiler, but rather with your source code.

  • if you observe a problem goes away by changing optimization levels, the actual problem is pretty much guaranteed not to be with the compiler, but rather with your source code

    +1