2017-10-04 188 views
1

因此,您可能會從前幾天識別出我在IDE中運行此代碼時出現的類似問題。最終,我得到的建議是,我應該學會從命令行一起運行它們。因此,我接受了建議,並從Codesourcery Lite MentorGraphics安裝了GNU工具鏈(不知道這是否合理)。我可以做的命令是類似的東西使用GNU ToolChain在Windows命令行上運行ARM/C

> 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」但我不知道是什麼的工作確實。

這裏是我的代碼:

ARM

.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} 

Ç

#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上安裝了apt-get from Bash,所以如果你有一個BASH解決方案也是可能的(https://packages.ubuntu.com/trusty/devel/gcc-arm-none-eabi

+0

你得到了什麼錯誤? –

+0

對於哪個命令? – wjmccann

+0

爲你得到它的每一個命令。 –

回答

1

如果有人遇到過這種情況,我最終得到它的方式將這些腳本行輸入到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)