line assembly help

Joel Sherrill joel.sherrill at OARcorp.com
Sun Jun 17 13:05:46 UTC 2001


Or you could just use the macros provided inside each RTEMS
port that provide this functionality.  CPU_swap_u32 and
CPU_swap_u16.  The i386 version is implemented as a macro
wrapper of this routine:

static inline unsigned int i386_swap_U16(
  unsigned int value
)
{
    unsigned short      sout;

    __asm__ volatile( "rorw $8,%0" : "=r"  (sout) : "0"   (value));
    return (sout);
}   

Marc Salem wrote:
> 
> You are missing the constaints part of the asm statement. See the
> 'info gcc' pages, under "C extensions", and "extended asm".
> 
> Or a http version of the same:
> http://www.psc.edu/general/software/packages/gcc/manual/gcc_85.html
> 
> Basically you need to tell gcc how the assembly code should get at the
> data. I am blissfully ignorant of the intel instruction set, so i
> can't really help with the details.
> 
> Here is an example using the ARM swap instruction, which is similar:
> 
> INLINE dword_t
> swap (dword_t * addr, dword_t val) {
> 
>   __asm__ __volatile__ ("\tswp  %0, %0, [%1]    \n"
>                   : "=r" (val)
>                   : "r" (addr), "0" (val)
>                   );
> 
>   return val; /* Now containing original value */
> }
> 
> On Sat, Jun 16, 2001 at 09:27:18PM -0000, Heamanth  Kumar wrote:
> > Hello,
> >        I'm trying to compile some code with a small bit of assembly for byte swaping with gcc. I get linking errors. I'm new to Assembly Can any body help.
> >
> > the code is
> >    xchg(us) \
> >     __asm__("
> >         mov us,%ax
> >         xchg %al,%ah
> >         mov %ax,us
> >         ");
> >
> >
> > When I call this function to swap I get a link error like
> > (.text+)x8): undefined reference to 'us'
> >
> > ld returned 1 exit status
> >
> > Any help would be appreated..
> > My host is RH Linux for i386 target..
> >
> > Heamanth
> >
> >
> >
> >
> >
> >
> >
> >
> > _____________________________________________________
> > Buy Lagaan & Yaadein music for 30% less.
> > Avail this special offer at http://shopping.rediff.com/shopping/music/offerrediffmailer.htm
> >
> >
> 
> --
> 
> Marc Salem
> m.salem at unsw.edu.au
> 0416 033 180
> 
> UNSW Solar Racing Team          School Of Computer Science & Engineering
> http://www.sunswift.com/        http://www.cse.unsw.edu.au/

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985



More information about the users mailing list