> Am Fri, 30 Jun 2006 11:20:03 +0200 schrieb David Brown:
> >>
> >>   mov.b &0x0034, r15
> >>   add r15, r15
> >>   mov r15, &two
> >>   ret
> >
> > That would be wrong.  PINB is declared volatile - the C code says it
should
> > be read twice, so it should be read twice by the generated assembly.
Thus
> > better code would be:
>
> Thinking 'embedded' seems to be quite different than thinking 'C'. ;-)
> I agree with that. But your code
>
> > mov.b &0x0034, r15
> > add.d &0x0034, r15
> > mov r15, &two
> > ret
>
> adds a 8 bit number to a 16 bit number where adding to 8 bit numbers
> is needed. ;-)
>

You're right - my code (after correcting the typo ".d" to ".b") would miss
the carry.  So we were both wrong!

Just for fun, I tried compiling the code with "two" changed to an unsigned
char.  My mps430 compiler (3.2.3) then gives

    mov.b &P6IN, r15
    rla.b r15
    mov.b r15, &two
    ret

In other words, it makes the same mistake you did and disregards the
"volatile" qualifier.  This is far more serious than the original question -
it is incorrect code, rather than just inefficient code.  The same mistake
is made if the volatile variable and the destination variable are both
16-bit wide.

avr-gcc (3.4.5) generates correct code, so I presume this is an msp430-gcc
specific issue rather than a general gcc issue.

mvh.,

David



Reply via email to