Am Wed, 28 Jun 2006 19:59:27 +0000 (UTC) schrieb Grant Edwards:
> Can anybody explain the code generated for this function?
>
> #include <io.h>
>
> unsigned two;
>
> void foo(void)
> {
> two = P6IN + P6IN;
> }
>
> 21 foo:
>
> 26 0000 5F42 3400 mov.b &0x0034, r15
> 27 0004 4E4F mov.b r15, r14
> 28 0006 5F42 3400 mov.b &0x0034, r15
> 29 000a 7FF3 and.b #-1,r15
> 30 000c 0E5F add r15, r14
> 31 000e 824E 0000 mov r14, &two
> 32 0012 3041 ret
>
> Why the extra mov.b?
Which extra mov.b? There are two extra mov.b (see below).
> Why the and.b?
Too less optimizing within the compiler?
> Why isn't this correct?
>
> mov.b &0x0034, r15
> mov.b &0x0034, r14
> add r15, r14
> mov r14, &two
> ret
This *is* correct. But if you really want to deal with assembler
(which I do prefer on the msp430), you could code as follows:
mov.b &0x0034, r15
add r15, r15
mov r15, &two
ret