【发布时间】:2020-03-01 03:27:08
【问题描述】:
这是我的 ARM7 程序集 sn-p
.global strCopy
.text
strCopy:
strCopyloop:
LDRB R2, [R1], #1
STRB R2, [R0], #1
CMP R2, #0
BNE strCopyloop
Bx LR
这是使用这个函数的 C 文件
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
extern void strCopy(char* strTo, const char* strFrom);
int main(){
const char* str1 ="This one";
char* str2;
strCopy(str2,str1);
return 0;
}
我一生都无法弄清楚为什么它给了我一个分段错误。
【问题讨论】:
-
你还没有为
str2分配空间。 -
它会以与普通
strcpy相同的方式崩溃。使用调试器查看您正在向 asm 传递一个错误指针(无论是在未初始化的str2本地变量中的什么)。
标签: c assembly segmentation-fault arm7