所以当我问了一个关于在 IDE 中运行此代码的类似问题时,您可能会认出我。最终我得到的建议是我应该学会从命令行一起运行它们。因此,我接受了建议并从 Codesourcery Lite MentorGraphics 安装了 GNU 工具链(不确定这是否有意义)。我可以做的命令是
> arm-none-eabi-gcc -o main main.c -T script
但是,我无法准确找出我应该如何使用这些命令。我试过了
> arm-none-eabi-gcc -o main (my c filename).c -T (my ARM filename).s
但是我从 ARM 文件中得到一个语法错误。然后我试着做
> arm-none-eabi-gcc -o main (my c filename).c
但这不起作用,因为外部“add2”
> arm-none-eabi-as add2.s
这给了我一个文件“a.out”,但我不知道它是做什么的。
这是我的代码:
手臂
.global add2
add2:
stmfd sp!, {v1-v6, lr} @ 'standard' entry, save registers on the stack
add a1, a1, a2 @ do the addition requested
ldmfd sp!, {v1-v6, pc}
C
#include <stdio.h> /* standard input and output */
#include <stdlib.h> /* standard library */
extern int add2(int i, int j); /* tell the compiler that the routine is not defined here */
int main(int argc, char * argv[]) /* entry point to the program */
{
int i, j; /* declare the variable types */
int answer;
i = 5; /* give the variables values */
j = 20;
answer = add2(i, j); /* call the assembly language routine */
printf("result is : %d\n", answer); /* print out the answer */
exit(0); /* leave the driver program */
}
任何帮助,将不胜感激。我还在 Windows 上的 Ubuntu 上从 Bash 的 apt-get 安装了这个工具包,所以如果你有一个 BASH 解决方案也是可能的(https://packages.ubuntu.com/trusty/devel/gcc-arm-none-eabi )