I made a few errors in this short post...
Destination register should be on the left:
unsigned long retval
asm volatile ("mov %0, sp" : "=r" (retval) : /* no inputs */ );
return retval;
and the __asm keyword only works if you include the register keyword and
this will generate a warning about using an uninitialized variable:
register unsigned long stackptr __asm("sp");
return stackptr;
Regards,
Richard Duits
Richard Duits wrote:
> Copying one register to another is done with the "mov" instruction:
>
> unsigned long retval
> asm volatile ("mov sp, %0" : "=r" (retval) : /* no inputs */ );
> return retval;
>
> An alternative in this case would be:
>
> unsigned long stackptr __asm("sp");
> return stackptr;
>
> Regards,
> Richard Duits
>
>
> Bill Knight wrote:
>
> > On Mon, 11 Jul 2005 15:00:32 -0000, xjag74 wrote:
> >
> > >Hi,
> >
> > >I wonder why GCC don't compile that simple code:
> >
> > >static inline unsigned StackPointerValue(void)
> > >{
> > > unsigned long val;
> > > asm volatile (" str R13, retval");
> > > return val;
> > >}
> >
> > >When I try to compile the following error appears:
> > >"Internal_relocation (type: OFFSET_IMM) not fixed up"
> >
> > >What does that mean? How can I get that running?
> >
> >
> > 1st, 'retval' is not 'val'
> >
> > I haven't compiled this but try
> >
> > static inline unsigned StackPointerValue(void)
> >
> > unsigned long retval;
> > asm volatile (" str sp, %0" : "=r" (retval) : /* no inputs */ );
> > return retval;
> >
> >
> > Regards
> > -Bill Knight
> > R O SoftWare &
> > http://www.theARMPatch.com
> >
> >
> >
> >
> > ------------------------------------------------------------------------
> > YAHOO! GROUPS LINKS
> >
> > * Visit your group "lpc2000
> > <http://groups.yahoo.com/group/lpc2000>" on the web.
> >
> > * To unsubscribe from this group, send an email to:
> > lpc2000-unsubscribe@yahoogroups.com
> > <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
> >
> > * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> > Service <http://docs.yahoo.com/info/terms/>.
> >
> >
> > ------------------------------------------------------------------------
> >
>
>
> ------------------------------------------------------------------------
> YAHOO! GROUPS LINKS
>
> * Visit your group "lpc2000
> <http://groups.yahoo.com/group/lpc2000>" on the web.
>
> * To unsubscribe from this group, send an email to:
> lpc2000-unsubscribe@yahoogroups.com
> <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>
> ------------------------------------------------------------------------
>Message
Re: [lpc2000] GNU inline assembler return value
2005-07-11 by Richard Duits
Attachments
- No local attachments were found for this message.