-1

所以,我需要运行我已经完成的某个 arm32 代码。代码没问题,并且使用 Keil 在我的 Windows 机器上运行,但是当我尝试在arm-linux-gnueabihf-as prgm1.s -o asm32.o && arm-linux-gnueabihf-ld -static asm32.o -o asm32arm32 的 Ubuntu 交叉编译器(使用)上运行时,它会出现很多语法错误。我想也许我在错误的架构上运行,但我根本找不到正确的架构。在 Keil 上,我选择运行的设备是 LPC2104。Ubuntu 交叉编译器中是否有任何设备规范?或者我可以用来运行它的另一个程序?代码和错误如下:

AREA prgm1, CODE, READONLY 
        ENTRY

main    MOV R1, #2
        BL func1
        MOV R9, R8 ;MOV F(2) into R9
        MOV R1, #5
        BL func1
        
                
stop    B stop

func2   MUL R2, R6, R3 ;Multiplies bk with x0
        ADD R0, R5, R2 ;Adds the results of the previous line with ak-1
        BX LR ;Output Value


func1   MOV R6, #1 ;MOV the first coefficient into R6
        MOV R5, #3 ;MOV the second coefficient into R5
        MOV R3, R1 ;MOV the input to R3
        PUSH{LR} ;Pushes back to the main
        BL func2 ;Call function to output
        MOV R6, R0 ;MOV the ouput value to R6
        MOV R5, #5 ;Third Coefficient
        BL func2 
        MOV R6, R0
        MOV R5, #7
        BL func2
        MOV R6, R0
        MOV R5, #9
        BL func2
        MOV R8, R0
        POP{LR} ;POP LR from the stack 
        BX LR
        END

还有错误(对不起,我不知道如何将其更改为英文):

prgm1.s:12: Erro: instrução inválida `area prgm1,CODE,READONLY'
prgm1.s:13: Erro: instrução inválida `entry '
prgm1.s:15: Erro: instrução inválida `main MOV R1,#2'
prgm1.s:17: Erro: registrador ARM esperado -- `mov F(2)into R9'
prgm1.s:22: Erro: instrução inválida `stop B stop'
prgm1.s:24: Erro: instrução inválida `func2 MUL R2,R6,R3'
prgm1.s:24: Erro: instrução inválida `multiplies bk with x0'
prgm1.s:25: Erro: registrador ARM esperado -- `adds the results of the previous line with ak-1'
prgm1.s:26: Erro: instrução inválida `output Value'
prgm1.s:29: Erro: instrução inválida `func1 MOV R6,#1'
prgm1.s:29: Erro: registrador ARM esperado -- `mov the first coefficient into R6'
prgm1.s:30: Erro: registrador ARM esperado -- `mov the second coefficient into R5'
prgm1.s:31: Erro: registrador ARM esperado -- `mov the input to R3'
prgm1.s:32: Erro: instrução inválida `push{LR}'
prgm1.s:32: Erro: instrução inválida `pushes back to the main'
prgm1.s:33: Erro: instrução inválida `call function to output'
prgm1.s:34: Erro: registrador ARM esperado -- `mov the ouput value to R6'
prgm1.s:35: Erro: instrução inválida `third Coefficient'
prgm1.s:44: Erro: instrução inválida `pop{LR}'
prgm1.s:44: Erro: expressão muito complexa -- `pop LR from the stack'
prgm1.s:46: Erro: instrução inválida `end'
4

1 回答 1

1

汇编语言特定于工具(gas、armasm 等)而不是目标 (ARM)。这些是不同且不兼容的编程语言。

可能只是摆脱这个或寻找替代方案。

AREA prgm1, CODE, READONLY 
        ENTRY



main    MOV R1, #2
        BL func1
        MOV R9, R8 ;MOV F(2) into R9
        MOV R1, #5
        BL func1

标签必须有一个冒号。Gas,使用@作为注释,而不是大多数汇编语言使用的注释;

main:    MOV R1, #2
        BL func1
        MOV R9, R8 ;@MOV F(2) into R9
        MOV R1, #5
        BL func1

我喜欢放 ;@ 并且它适用于两者,或者至少您的文本编辑器可能会更快乐。

这可能涵盖这里的所有问题。也许 .end 而不是 end 或者只是将其注释掉。

除非您将标签声明为全局标签,否则标签假定为本地标签

.globl main
...
main:

同样,您想将其声明为函数。

.globl main
.type main, %function
...
main:

这样它就可以正确链接。与其他汇编程序一样,您需要指定目标架构(armv4t、armv6-m、armv7-a 等)。如果你使用统一的语法

.syntax unified

顶部的某个地方(根据需要也可以使用 .thumb)

于 2021-10-18T03:26:22.957 回答