使用GNU ToolChain在Windows命令行上运行ARM / C.

因此,当我问一个关于在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  /* standard input and output */ #include  /* 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 )

如果有人遇到这种情况,我最终使用它的方法是在Windows命令行中键入这些脚本行:

 Step 1: Compile your c-file arm-none-eabi-gcc -o (object file name 1) -c (c file name) Step 2: Assemble your ARM file arm-none-eabi-gcc -o (object file name 2) -c (ARM file name) Step 3: Link files and create executable arm-none-eabi-gcc -o (executable file name) (object file name 1) (object file name 2) -T armulator-ram-hosted.ld Step 4: Run the files arm-none-eabi-run (executable file name)