This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: question about writing assembly in c


Hi ,

This is more a question for gcc-help@ rather than binutils@ .However
I'll answer your question but please follow up on gcc-help@gcc.gnu.org
instead of here.

On Fri, Jan 9, 2009 at 2:14 PM, loody <miloody@gmail.com> wrote:
> Dear all:
> At the end of the letter is the macro excerpted from include\asm-arm\irqflags.h.
> I have check the as.pdf but still have questions below:
> 1. what is "%0" used for? Is that mean r0? After checking the
> assembly, it is translated as 'r3'.
>    or %0 means the first one available register?

%0 operand 0 or the 1st operand provided in the extended inline
specification. In your case you have asked for this to be an output
operand into the variable temp and told gcc that you need it in a
register. Further you've told gcc that you want to write to that
register. There used to be a guide called Brennan's guide to extended
inline assembly which I used when I was a kid in college many many
moons ago. I'm pretty sure google can find it for you and you'd find
it useful .

> 2. what are the last 4 lines used for
>        : "=r" (temp)                                           \
>        :                                                       \
>        : "memory", "cc");                                      \
> appreciate your help,
> miloody

"=r"(temp) -> Put the variable temp in register and assign to it .
It's written in here.  (Output register)
memory - > memory is clobbered here.
cc -> condition code register is clobbered. (Clobber list for this and memory)

I'd suggest you read that guide and you'll find these making some more sense.

HTH

Ramana

>
>
> #define raw_local_irq_enable()                                  \
>        ({                                                      \
>                unsigned long temp;                             \
>        __asm__ __volatile__(                                   \
>        "mrs    %0, cpsr                @ local_irq_enable\n"   \
> "       bic     %0, %0, #128\n"                                 \
> "       msr     cpsr_c, %0"                                     \
>        : "=r" (temp)                                           \
>        :                                                       \
>        : "memory", "cc");                                      \
>        })
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]