問題描述
錯誤:ARM 的行尾出現垃圾 ‑as 和 ‑o 錯誤 (Error: Junk at end of line ‑as and ‑o error with ARM)
我正在嘗試編寫我的第一個 ARM 程序,當我嘗試運行“as ‑o labl1.o lab1.s”時出現此錯誤
lab1.s:3: Error: junk at end of line, first unrecognized character is `s'
我非常不確定自己做錯了什麼在這裡,因為我唯一使用 s 的時間是在我的 2 個字符串中,並且對我出錯的代碼位置感到非常困惑。
@Data
.data
string1: .asciz
string2: .asciz
@Code
.text
.global main
.extern printf
main:
push {ip, lr}
push {r0, r1, r2}
ldr r0, =string1
mov r1, #34
mov r2, #56
bl printf
pop {r0,r1,r2}
push {r0}
ldr r0, =string2
bl printf
pop {r0}
pop {ip, pc}
非常感謝鏈接到有用的文檔或幫助調試,謝謝!
參考解法
方法 1:
You may be confusing the address of your strings and the values you want to assign them: As specified in GNU as documentation, the .asciz
directive does require a string argument ‑ a slightly modified version of your code does assemble correctly:
.data
string1: .asciz "string1"
string2: .asciz "string2"
string1
is now the label for the address where bytes "string1\x00
" are located, and string2
is the label for the address where bytes "string2\x00"
are.