我试图在树莓派3上编写一个基本的arm汇编文件,该文件可以通过gcc编译器访问printf和scanf,但是在编译代码时出现了一个奇怪的错误。
这是我用汇编语言编写的第三个使用gcc编译器的应用程序,所以我想进行增量测试,所以我设置了提示和字符串,然后尝试干净退出。但是,这是引发错误的代码:
.data
.balign 4
promptNum1: .asciz “Please enter some number that you want to work with”
.balign 4
inputNum1String: .asciz “%d”
.balign 4
outputString: .asciz “Your answer is %d”
.balign 4
return: .word 0
.balign 4
signPrompt: .word “What do you want the numbers to do?\n 1)add \n 2)subtract\n 3)multiply\n 4)divide”
.text
.global main
main:
ldr r11, addressOfReturn
str lr, [r11]
.
.
.
ldr r11, addressOfReturn
ldr lr, [r11]
bx lr
addressOfPromptNum1: .word promptNum1
addressOfInputNum1String: .word inputNum1String
addressOfOutputString: .word outputString
addressOfReturn: .word return
我希望可以像以前的代码一样进行编译,但是,我的错误引用了提示行Num1,inputNum1String,outputString,signPrompt上无法识别的字符。但是,无法识别的字符是 0xe2 ,在查找后我发现编译器无法识别的字符根本不在文件中。 < / p>
答案 0 :(得分:3)
代码中的引号是“智能引号”(utf-8序列e2 80 9c
和e2 80 9d
),在汇编程序中不能很好地发挥作用。将它们更改为常规引号就可以了。
.data
.balign 4
promptNum1: .asciz "Please enter some number that you want to work with"
.balign 4
inputNum1String: .asciz "%d"
.balign 4
outputString: .asciz "Your answer is %d"
.balign 4
return: .word 0
.balign 4
signPrompt: .word "What do you want the numbers to do?\n 1)add \n 2)subtract\n 3)multiply\n 4)divide"
.text
.global main
main:
ldr r11, addressOfReturn
str lr, [r11]
.
.
.
ldr r11, addressOfReturn
ldr lr, [r11]
bx lr
addressOfPromptNum1: .word promptNum1
addressOfInputNum1String: .word inputNum1String
addressOfOutputString: .word outputString
addressOfReturn: .word return