2016-11-27 3 views
0

J'ai joint mon code à cet article. Cependant, quand je l'exécute sur gdb, une fois qu'il balaye le premier numéro et le second numéro, il me donne un "signal reçu par le programme SIGSEGV, erreur de segmentation". Erreur. J'apprécierais toute aide pour corriger ceci. Merci!SPARC Assembly Scanf Error

.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 
+2

Bien que vous ayez essayé d'utiliser 'gdb' mais essayez de l'utiliser pour un meilleur effet;) Regardez quelle instruction est défectueuse et pourquoi. De plus, commentez votre code, surtout si vous voulez que les autres vous aident. Le 'ajouter% o1,% o2,% o3' n'a aucun sens (ajouter deux pointeurs). De plus, vous semblez faire confiance aux registres '% o' qui sont conservés et qui sont cependant sauvegardés. De plus, la seconde invocation de 'scanf' définit'% o2' au lieu de '% o1'. – Jester

+0

@Jester Merci! J'ai été capable de trouver la réponse grâce à votre aide. – Jay

Répondre

0

j'ai pu comprendre le problème grâce à l'aide Stefan et bouffon!

! SungJae Kim 

! b321024 ! Affectation 5 ! 2 décembre 2016

.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 %d\n" 

.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 
0

Je pense qu'il devrait ressembler davantage à cela, mais je n'ai jamais écrit ensemble SPARC 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 %d\n" 

.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 
+0

Merci! J'ai été capable de trouver la réponse grâce à votre aide. – Jay