我已將此代碼附加到此帖子。但是,當我在gdb上運行它時,一旦它掃描了第一個數字和第二個數字,它就會給我一個「程序接收到的信號SIGSEGV,分段錯誤」。錯誤。 我將不勝感激任何幫助來糾正這一點。 謝謝!SPARC裝配Scanf錯誤
.align 4
.section ".bss"
input: .skip 4
.section ".data"
format: .asciz "%d"
string1: .asciz "Enter Number 1:\n"
string2: .asciz "Enter Number 2:\n"
string3: .asciz "The sum of %d and %d is %d\n"
.section ".text"
.global main
main:
save %sp, -96, %sp
set string1, %o0
call printf
nop
set format, %o0
set input, %o1
call scanf
nop
set string2, %o0
call printf
nop
set format, %o0
set input, %o2
call scanf
nop
add %o1, %o2, %o3
set string3, %o0
ld [%o1], %o1
ld [%o2], %o2
ld [%o3], %o3
call printf
nop
ret
restore
mov 1, %g1
ta 0
好,你試圖用'gdb'但嘗試用它來效果更佳;)看看這些指令斷層和原因。此外,請評論你的代碼,特別是如果你想讓別人幫忙。 'add%o1,%o2,%o3'沒有任何意義(增加兩個指針)。此外,您似乎依賴於保存被調用者保存的'%o'寄存器。另外,第二次調用'scanf'則設置'%o2'而不是'%o1'。 – Jester
@Jester謝謝!感謝您的幫助,我能夠找出答案。 – Jay