wang congxian

problem with optimization

Discussion created by wang congxian on Mar 30, 2009
Latest reply on Apr 1, 2009 by wang congxian

I use cw6.4 and when I use optimization it comes out an annoying problem.

the optimization setting are:

            optimization level 4;

            IPA FILE level  optimization;

 

codes as follows:

void Delay20(void)
{                                                       

    KEYCNT=0;
    while(KEYCNT<=19)
    {
//    asm{NOP};                           
    }


}

 

If I do not use  asm{NOP}; the result of disassmble are :

; 2808: void Delay20(void)
; 2809: {                                                         
; 2810: 
; 2811:     KEYCNT=0;
; 2812:     while(KEYCNT<=19)
; 2813:     {
; 2814: 
; 2815: //    asm{NOP};                             
;
0x00000000                    _Delay20:
;                             Delay20:
0x00000000  0x4E560000               link     a6,#0
;
; 2816:     }
; 2817: 
; 2818: 
;
0x00000004  0x60FE                   bra.s    *+0                   ; 0x00000004
;
; 2819: }
0x00000006  0x4E71                   nop     

 

 

And if use  asm{NOP};  the result of disassmble are :

 

 ; 2807: //~~~~~~~delay20ms~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
; 2808: void Delay20(void)
; 2809: {                                                        
; 2810:  
;
0x00000000                    _Delay20:
;                             Delay20:
0x00000000  0x4E560000               link     a6,#0
;
; 2811:     KEYCNT=0;
; 2812:     while(KEYCNT<=19)
; 2813:     {
; 2814:  
;
0x00000004  0x42B900000000           clr.l    _KEYCNT
0x0000000A  0x7013                   moveq    #19,d0
0x0000000C  0x6002                   bra.s    *+4                   ; 0x00000010
;
; 2815:     asm{NOP};                            
;
0x0000000E  0x4E71                   nop      
;
; 2816:     }
; 2817:  
; 2818:  
;
0x00000010  0xB0B900000000           cmp.l    _KEYCNT,d0
0x00000016  0x64F6                   bcc.s    *-8                   ; 0x0000000e
;
; 2819: }
0x00000018  0x4E5E                   unlk     a6
0x0000001A  0x4E75                   rts      

 

why thy are so different ?It is quite annoying>...

Outcomes