[email protected] wrote:
> 
> 2) Mark it as inline.  E.g. in a header file, include
> 
> static inline uint16_t __attribute__((const))
> convert_endian(uint16_t dt)
> {
>       asm("swpb %0" : "+g" (dt));
>       return dt;
> }
> 
> Since it's only one instruction anyway, that will let mspgcc just
> drop that one instruction in wherever it's needed.
> 
> (Unfortunately, while it does a good job with register variables,
> I haven't managed to convince it to generate "swpb @r15+" even when
> spoon-fed code that should generate it.  Oh, well.)
> 

This does not work if I use this code:
------------------------------------------------------------------------------
/*
  endian.c
*/
#include <stdint.h>

static inline uint16_t endian16(uint16_t v)
{
  asm("swpb %0" : "+g" (v));
  return v;
}

volatile uint16_t value;
int main()
{
  value = 0x1122;
  endian16(value);

  //At this point: value = 0x1122 !!!!
  return (int)value;
}//main
------------------------------------------------------------------------------

And I compile using:

msp430-gcc -g3 -mmcu=msp430x149 -o endian.msp endian.c -Wall -O2

The function 'endian16' (with or without __attribute__((const))) compile to
nothing!! Maybe a problem of mspgcc with inline assembler in static inline
functions? I work with msp430-gcc 3.2.3 compiled from CVS (2006-04-10).


If I use a macro to inline the assembler, it works fine (and very optimized):
------------------------------------------------------------------------------
/*
  endian.c
*/
#include <stdint.h>

#define endian16(v)  asm("swpb %0" : "+g" (v))

volatile uint16_t value;
int main()
{
  value = 0x1122;
  endian16(value);

  //At this point: value = 0x2211
  return (int)value;
}//main
------------------------------------------------------------------------------

Any comments? Maybe a bug? Greetings,

Mario Palomo



Reply via email to