我正在尝试使用 cortex M4 处理器(我买了一 block Atmel SAM4C 板)混合 C 代码和 asm。
我正在尝试一个不起作用的简单代码(但它确实可以编译)。
我唯一的调试选项是使用 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);
}
汇编代码:
.global asmfunc
asmfunc:
MOV pc, lr
向 UART 发送一些数据后,我应该收到 2 倍的值“0”。但是,我只收到一次。我可以假设我的 asm 函数有问题,但我找不到问题。
我试图找到一些文档,我认为我做对了但是......
最佳答案
asmfunc:
MOV pc, lr
这是 ARM 程序集,不是 Thumb 程序集。您没有在 Thumb 模式下组装它,这导致生成的代码对于 Cortex-M CPU 无效。
将汇编程序设置为 Thumb 模式并使用适当的操作:
.thumb
.syntax unified
.global asmfunc
asmfunc:
bx lr
关于c - 混合 C 和 ASM,皮质 M4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28504089/