On 2006-06-30, Bodo Rzany <[email protected]> wrote:
> 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).
No there, is one extra.
>> Why the and.b?
>
> Too less optimizing within the compiler?
I can't even think of any reason why you would and a register
with -1 except to set the condition flags, but the conditions
flags are a) never used, b) overwritten by the next instruction
anyway.
>> 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
Since P6IN is volatile, that code is incorrect.
--
Grant Edwards grante Yow! .. If I cover this
at entire WALL with MAZOLA,
visi.com wdo I have to give my AGENT
ten per cent??