【发布时间】:2015-02-13 16:24:07
【问题描述】:
我正在尝试使用 cortex M4 处理器(我买了一块 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);
}
asm 代码:
.global asmfunc
asmfunc:
MOV pc, lr
在向 UART 发送一些数据后,我应该收到 2 倍的值“0”。但是,我只收到一次。我可以假设我的 asm 函数有问题,但我找不到问题。
我试图找到一些文档,我认为我做得对,但是......
【问题讨论】:
-
您在 cmets 中说 get_data / send_data 获取并发送 32 位字的 4 个字节......但您继续说您希望收到 2 个“0”字节。你不认为这是你的 ASM 代码的问题。在所有动作之后调用它。请发布 get_data 和 send_data 来源
-
看起来足够无害。您是否尝试过评论您的
asmfunc()电话,看看您是否得到了 2 个零?您是否尝试过添加无限循环以使main不会返回?也许您在发送数据之前返回,然后 cpu 停止或其他什么。 -
我认为调用可能由于优化而不会发生,因为很明显不需要调用函数。您在实际装配中看到调用了吗?
-
@Greycon 我认为 OP 意味着他希望收到他的程序发送到终端的两个 0,因为他发送一个 0,调用他的 asm 函数,然后发送另一个 0。因为终端只收到一个 0,OP 断定 asm 函数没有返回。
-
Doh,我错过了 asm 调用后的第二个 send_data。今天是星期五:-)