混合C和ASM,皮质M4

时间:2015-02-13 16:24:08

标签: c assembly cortex-m

我正在尝试使用皮质M4处理器混合使用C代码和asm(我买了一台Atmel SAM4C板)。

我正在尝试一个不起作用的简单代码(但它确实可以编译)。

我唯一的调试选项是使用UART(我现在没有任何调试器)。

基本上,我只想写一个什么都不做的asm函数(直接返回C代码)。

这是我的C代码:

#include <asf.h>
extern uint32_t asmfunc(void);

int main (void){

    //some needed initialisation to use the board
    sysclk_init();
    board_init(); 

    uint32_t uart_s = 0, uart_r;

    //get_data and send_data get/send the 4 bytes of a 32 bits word
    //they work, I don't show the code here because we don't care

    get_data(&uart_r); //wait to receive data via uart
    send_data(uart_s); //send the value in uart_s

    asmfunc(); 

    send_data(uart_s);
}

asm代码:

.global asmfunc

asmfunc:
MOV pc, lr

在向UART发送一些数据后,我应该收到2倍的值&#34; 0&#34;。但是,我只收到一次。我可以假设我的asm功能存在问题,但我无法找到。

我试图找到一些文档,我认为我做得对,但是......

1 个答案:

答案 0 :(得分:2)

asmfunc:
MOV pc, lr

这是ARM程序集,而不是Thumb程序集。您不是在Thumb模式下组装它,这会导致生成的代码对Cortex-M CPU无效。

将汇编程序设置为Thumb模式并使用适当的操作:

.thumb
.syntax unified

.global asmfunc
asmfunc:
    bx lr
相关问题