SPARC组件SCANF错误



我已经将代码附加到了这篇文章。但是,当我在GDB上运行它时,一旦它扫描了第一个数字和第二个数字,它就会给我一个"接收到的Sign Sigsegv,分段故障"。错误。我将感谢任何纠正此事的帮助。谢谢!

 .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 %dn"
    .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

我认为它应该看起来更像是这样,但我从来没有写过sparc assembly o:)

.align 4
.section        ".bss"
input1: .skip 4
input2: .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 %dn"
.section        ".text"
.global main
main:
save %sp, -96, %sp
set string1, %o0
call printf
set format, %o0
set input1, %o1
call scanf
set string2, %o0
call printf
set format, %o0
set input2, %o1
call scanf
set input1, %o1
ld [%o1], %o1
set input2, %o2
ld [%o2], %o2
add %o1, %o2, %o3
set string3, %o0
call printf
nop
ret
restore
mov 1, %g1
ta 0

我能够弄清问题,这要归功于Stefan和Jester!

! SungJae Kim

!B321024呢作业5呢2016年12月2日

.align 4
.section    ".bss"
input1: .skip 4
input2: .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 %dn"
.section    ".text"
.global main
main:
save %sp, -96, %sp
set string1, %o0
call printf
nop
set format, %o0
set input1, %o1
call scanf
nop
set string2, %o0
call printf
nop
set format, %o0
set input2, %o1
call scanf
nop
set input1, %o1
ld [%o1], %o1
set input2, %o2
ld [%o2], %o2
add %o1, %o2, %o3
set string3, %o0
call printf
nop
ret
restore
mov 1, %g1
ta 0

相关内容

  • 没有找到相关文章

最新更新