I have simple delay loop as:
void delay(unsigned int d) {
while(d--){
nop();
nop();
}
}

I was expecting that this function will use only one register (r15), as it doesn't declare anything. To my supprise dissassembly is very complicated. Does anyone know why it is so? And what is add #6, r5
Also another thing: while(d--) syntax.
I understand above syn. as
AGAIN:  cmp d
        jnz X
        add #-1,d
        jmp AGAIN
X:
as opposite to while (--d) syntax which is realized as below.



void delay(unsigned int d) {
    1140:       05 12           push    r5              ;
    1142:       04 12           push    r4              ;
    1144:       05 41           mov     r1,     r5      ;
    1146:       35 50 06 00     add     #6,     r5      ;#0x0006
    114a:       21 83           decd    r1              ;
    114c:       04 41           mov     r1,     r4      ;
    114e:       84 4f 00 00     mov     r15,    0(r4)   ;
   while(d--) {
    1152:       b4 53 00 00     add     #-1,    0(r4)   ;r3 As==11
    1156:       b4 93 00 00     cmp     #-1,    0(r4)   ;r3 As==11
    115a:       01 20           jnz     $+4             ;abs 0x115e
    115c:       03 3c           jmp     $+8             ;abs 0x1164
      nop();
    115e:       03 43           nop                     
      nop();
    1160:       03 43           nop                     
    1162:       f7 3f           jmp     $-16            ;abs 0x1152
   }
}
    1164:       21 53           incd    r1              ;
    1166:       34 41           pop     r4              ;
    1168:       35 41           pop     r5              ;
    116a:       30 41           ret                     

Reply via email to