Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: Porting inline assembly gnu function to keil

2005-05-06 by peterburdine

--- In lpc2000@yahoogroups.com, "javida13" <javida13@y...> wrote:
> The following code came from the download area, UT050418A, by Bill 
> Knigh.  Currently, I'm looking at the Keil Tools and the two
> functions below will not compile.  If someone could help, I would 
> appreciate it.
> 
> 
> static inline unsigned __get_cpsr(void)
> {
>   unsigned long retval;
>   asm volatile (" mrs  %0, cpsr" : "=r" (retval) : /* no inputs*/  );
>   return retval;
> }
> 
> static inline void __set_cpsr(unsigned val)
> {
>   asm volatile (" msr  cpsr, %0" : /* no outputs */ : "r" (val)  );
> }

Sorry for the late response, I surgery and didn't check the group for
a while.  Here is the correct port.  I relies on the fact the the
compilier (hopefully) puts the first parameter in r0 and the return
value in r0.

static inline unsigned __get_cpsr(void)
{
    __asm { MRS R0, CPSR }
}

static inline void __set_cpsr(unsigned val)
{
    __asm { MSR CPSR_cxfs, R0 }
}

Or, if you don't like that you can use the keil specific instruction,
LDAV and STAV to put the CPSR value in a specific register and then
copy it to a local variable.

http://www.keil.com/discuss/docs/thread5775.htm#msg25753

--Peter

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.