hendrixjl
Posts: 50
Joined: Sun Nov 04, 2012 9:22 pm
Location: Huntsville, Alabama, USA

inline assembly in C

Wed Jan 16, 2013 12:34 am

I'm using a version of arm-none-eabi-gcc and it is not taking inline assembly in the midst of my c code. It is trying to compile and link asm like it is a plain function. I'm a bit flummoxed.
Sample below:

Code: Select all

void TimerInit()
{
    enum {
    	ONE_MILLISECOND=1000,
    	PRESCALE_CNTRL=0xF9
    };
	arm_timer_setup(ONE_MILLISECOND, ONE_MILLISECOND, PRESCALE_CNTRL, PRESCALE_IS_CLOCK_DIV_1, TWENTY_THREE_BITS);
    arm_timer_clear_irq();
    arm_timer_irq_enable();
    arm_timer_enable();
    enable_basic_interrupt(IRQ_ARM_TIMER);
    // Enable Interrupts
    asm(
    	    "mrs r0,cpsr\n\t"
    	    "bic r0,r0,#0x80\n\t"
    	    "msr cpsr_c,r0\n\t"
    	    "bx lr\n\t"
    );
}
../ucos_port/bsp.c:28:5: warning: implicit declaration of function 'asm' [-Wimplicit-function-declaration]
...
/Users/jonathanhendrix/git/ucos/ucosii/Debug/../ucos_port/bsp.c:28: undefined reference to `asm'
./ucos_port/bsp.o: In function `BSP_Init':
/Users/jonathanhendrix/git/ucos/ucosii/Debug/../ucos_port/bsp.c:40: undefined reference to `OS_CPU_ARM_InitExceptVect'
collect2: ld returned 1 exit status

hendrixjl
Posts: 50
Joined: Sun Nov 04, 2012 9:22 pm
Location: Huntsville, Alabama, USA

Re: inline assembly in C

Wed Jan 16, 2013 12:37 am

Just found the answer: use "__asm__" instead of "asm"

Return to “Bare metal, Assembly language”