How to fix 'Error: junk at end of line, first unrecognized character 0xe2' in Assembly

半世苍凉 提交于 2021-02-05 08:41:08

问题


I am trying to write a basic arm assembly file on my raspberry pi 3 that has access to printf and scanf through the gcc compiler, but upon compiling my code I get a strange error.

This is my third application written in assembly to use the gcc compiler, so I wanted to do incremental testing so I set up my prompts and strings, and I try and exit cleanly; however, this is my code that throws the error:

.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

I expect this to compile as my previous code did, however, my error references an unrecognized character on the lines with promptNum1, inputNum1String, outputString, signPrompt. However, the character that is unrecognized is 0xe2, and upon looking that up I found that the character that is not recognized by the compiler is not in my file at all.


回答1:


The quotes in your code are "smart quotes" (the utf-8 sequences e2 80 9c and e2 80 9d), which isn't playing well with the assembler. Change them to be regular quotes and you should be fine.

.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


来源:https://stackoverflow.com/questions/55987873/how-to-fix-error-junk-at-end-of-line-first-unrecognized-character-0xe2-in-as

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!