2016-05-05 6 views
0

Ich hatte den folgenden Fehler in meinem Code.Bitte helfen. Befehl verweist auf undefiniertes Symbol bei 0x00400014 [0x00400014] 0x0c000000 Jal 0x00000000 [Haupt]; 188: jal Haupt Dieser Code umwandeln Farenheit zu Celsious und CelsiusAnweisung verweist auf undefinierten Fehler in MIPS/QTSPIM jal 0x00000000 [Haupt]; 188: jal Haupt

.data 0x10008000 

.word 5,9,32 

message1: 
    .asciiz "Select the temparature scale:<C or F><ENTER" 
message2: .asciiz "Type the desired temperature <ENTER>" 
message3: asciiz "Temparature= " 

.text 

.globl main 

main: 
    li $v0,4 
    la $a0,message1 
    syscall 

    li $v0,12 
    syscall 

    move $t0,$v0 

    li $t1,70 
    li$t2,67 
beq $t0,$t1,Farenheit 
beq $t0,$t2,Celcius 

li $v0,10 
syscall 


Farenheit: 

    li $v0,4 
    la $a0,message2 
    syscall 


    li $v0,6 
    syscall 

    lui $gp, 0x1000 #I put in register $gp the number 0x10008000,which     
    ori $gp, $gp,0x8000 # shows in the middle of address of static data 

    lwc1 $f16, 0($gp) 

    cvt.s.w $f16, $f16 



     lwc1 $f18, 4($gp) 

    cvt.s.w $f18, $f18 


     div.s $f20 , $f16,f$18 

     lwc1 $f14, 8($gp) 

     cvt.s.w $f14 $f14 

     lwc1 $f12,$v0 

     sub.s $f12,$f12,$f14 

     mul.s $f0,$f20,$f12 


     la $a0,message3 
     li $v0,4 
     syscall 

     mov.s $f12,$f0 
     li $v0,2 
     syscall 


     jr $ra 


Celcius: 

    li $v0,4 
    la $a0,message2 
    syscall 


    li $v0,6 
    syscall 

    lui $gp, 0x100 
    ori $gp, $gp,0x8000 

    lwc1 $f16, 0($gp) 

    cvt.s.w $f16, $f16 



     lwc1 $f18, 4($gp) 

    cvt.s.w $f18, $f18 


     div.s $f20 , $f18,f$16 

     lwc1 $f14, 8($gp) 

     cvt.s.w $f14 $f14 

     lwc1 $f12,$v0 

     mul.s $f12,$f12,$f20 
     add.s $f0,$f12,$f14 

     la $a0,message3 
     li $v0,4 
     syscall 

     mov.s $f12,$f0 
     li $v0,2 
     syscall 


     jr $ra 

Antwort

3

Ihren Code Farenheit sauber nicht einmal zusammenstellen würde.

Mit $gp [mit hart codierten Offsets] auf die .word 5,9,32 zuzugreifen war Overkill. Das Setzen einer expliziten Adresse für die .data Sektion war wahrscheinlich auch nicht gut.

Der syscall gibt den Wert in $f0 und nicht$v0

Es gab einen viele von replizierten Code zwischen dem Celcius und Fahrenheit Abschnitten „float lesen“, die konsolidiert werden können.

Sie wurden mit jr $ra [Rückkehr aus Funktion], ohne die Berechnungsabschnitte tatsächlich Aufruf über jal

sollte es mehr Kommentare sein, den Fluss Ihrer Logik zu erklären. Vielleicht möchten Sie meine Antwort hier sehen: MIPS linked list, weil es einige Tipps für ASM-Stil und saubere Codierung hat.

Wie auch immer, hier ist den aufgeräumt, mit Anmerkungen versehen und Arbeitscode:

.data 

temp5:  .word  5 
temp9:  .word  9 
temp32:  .word  32 

msg_scale: .asciiz  "Select the temperature scale:<C or F><ENTER>" 
msg_temp: .asciiz  "Type the desired temperature <ENTER>" 
msg_out: .asciiz  "Temperature= " 
msg_nl:  .asciiz  "\n" 

    .text 

    .globl main 

main: 
    # prompt user for temp type/scale 
    li  $v0,4 
    la  $a0,msg_scale 
    syscall 

    # read in temp scale 
    li  $v0,12 
    syscall 
    move $t0,$v0 

    # output a newline 
    la  $a0,msg_nl 
    li  $v0,4 
    syscall 

    # prompt for temperature 
    li  $v0,4 
    la  $a0,msg_temp 
    syscall 

    # read in temperature 
    # NOTE: result comes back in $f0 and _not_ $v0 
    li  $v0,6 
    syscall 
    ###lwc1 $f12,$v0 
    mov.s $f12,$f0 

    lwc1 $f16,temp5    # get 5 
    cvt.s.w $f16,$f16 

    lwc1 $f18,temp9    # get 9 
    cvt.s.w $f18,$f18 

    lwc1 $f14,temp32    # get 32 
    cvt.s.w $f14,$f14 

    # do fahrenheit to celcius 
    li  $t1,'F' 
    beq  $t0,$t1,Farenheit 
    li  $t1,'f' 
    beq  $t0,$t1,Farenheit 

    # do celcius to fahrenheit 
    li  $t1,'C' 
    beq  $t0,$t1,Celcius 
    li  $t1,'c' 
    beq  $t0,$t1,Celcius 

    j  main_exit 

    # print results 
main_print: 
    la  $a0,msg_out 
    li  $v0,4 
    syscall 

    mov.s $f12,$f0 
    li  $v0,2 
    syscall 

    la  $a0,msg_nl 
    li  $v0,4 
    syscall 

    j  main 

main_exit: 
    li  $v0,10 
    syscall 

Farenheit: 
    div.s $f20,$f16,$f18   # get 5/9 
    sub.s $f12,$f12,$f14   # subtract 32 from temp 
    mul.s $f0,$f20,$f12   # multiply by 5/9 
    j  main_print 

Celcius: 
    div.s $f20,$f18,$f16   # get 9/5 
    mul.s $f12,$f12,$f20   # multiply by 9/5 
    add.s $f0,$f12,$f14   # add 32 
    j  main_print 
0

Erstmal Danke für die Unterstützung, es war sehr, sehr helpful.Sorry für meinen Stil i Anfänger sind in der Montage und in der Regel in programming.My Code wurde ein wenig verwirrt, weil ich eine unvollständige code.Let vervollständigen sollte meine you.This erklären, ist die Aussprache:

.data0x10008000 
    .word 5,9,32,100 
    .text 
     lui $gp, 0x100 
    ori $gp, $gp,0x8000 

    lwc1 $f16, 0($gp) 

    cvt.s.w $f16, $f16 



     lwc1 $f18, 4($gp) 

    cvt.s.w $f18, $f18 


     div.s $f20 , $f16,f$18 

     lwc1 $f14, 8($gp) 

     cvt.s.w $f14 $f14 

     lwc1 $f12,12($gp) 
     cvt.s.w $f12,$f12 

     sub.s $f12,$f12,$f14 

     mul.s $f0,$f20,$f12 

     jr $ra 

Sie diesen Code vervollständigen sollte und die Benutzeroberfläche hinzufügen (wie ich in meinem tat Code) und auch um einen Code zu syntaktisch zu kodieren farheneit zu celsius.That ist, warum habe ich verwirrt :(

+0

Dies sollte eine Bearbeitung der Frage oder etwas sein. Ich denke nicht, dass es eine tatsächliche Antwort sein soll, also bitte poste es nicht als Eins. –

0

hatte ich das gleiche Aufsatz für meine Universität (vielleicht haben Sie von Auth sind auch, wenn auch nicht Sinn geben nicht auf diese Konsole: P)

Bei Sie haben keine Antwort auf Ihr Problem mit Craigs Antwort gegeben, dann schauen Sie sich meinen Code an, der richtig funktioniert.

Ich denke nach Forschung (MIPS $gp register und über Internet), dass mit gp auf Daten zuzugreifen, die Sie im statischen Datensegment gespeichert sind, ist keine gute Methode, aber so wurde das Programm gesagt, getan zu werden!

Außerdem können viele Fehler auftreten, weil der Simulator nicht neu initialisiert wird!

Hier ist mein Code, hoffe ich habe eine Hand!

.data 0x10008000 
.word 5, 9, 32 
     message1: .asciiz "Select the temparature scale:<C or F>:" 
     message2: .asciiz "Type the desired temperature:" 
     message3: .asciiz "Temparature= " 
     newline: .asciiz "\n" 
.text 

.globl main 

main: 

li $v0,4 
la $a0,message1 
syscall        #prompt message 

#read the character 
li $v0,12 
syscall 

move $t0,$v0 

#check the character and branch          
li $t1,'F' 
beq $t0,$t1,Fahrenheit    
li $t1,'f' 
beq $t0,$t1,Fahrenheit    #fahrenheit to celsius 

li  $t1,'C' 
beq  $t0,$t1,Celsius 
li  $t1,'c' 
beq  $t0,$t1,Celsius   #celsius to fahrenheit 

li $v0,10 
syscall       #end program 

Fahrenheit: 

li $v0,4 
la $a0,newline 
syscall       #type new line 


li $v0,4       #type message 2 
la $a0,message2 
syscall    

li $v0,6 
syscall       #read float from user 

#gp has 0x10008000 
lui $gp, 0x1000 
ori $gp, $gp, 0x8000    #load to f16 number 5 

lwc1 $f16, 0($gp)     

cvt.s.w $f16, $f16    #convert to float 

lwc1 $f18, 4($gp)     #load number 9 to f18 

cvt.s.w $f18, $f18    #convert to float 


div.s $f20, $f16, $f18   #divide 5/9 and save it to f20 

lwc1 $f14, 8($gp)     #load number 32 

cvt.s.w $f14, $f14    #convert to float 


li  $v0,6      #read from user float 
mov.s $f12,$f0     

sub.s $f12, $f12, $f14   #Fahrenheit - 32 

mul.s $f0, $f20, $f12    #(Fahrenheit-32)*5/9 ,the result 

li $v0,4 
la $a0,newline 
syscall       #type new line 

li $v0,4 
la $a0,message3 
syscall       #type message 3 

mov.s $f12,$f0 
li  $v0,2 
syscall       #type the result 

jr $ra 

Celsius: 
li $v0,4 
la $a0,newline 
syscall       #type new line 


li $v0,4       #type message 2 
la $a0,message2 
syscall    

li $v0,6 
syscall       #read float from user 

lui $gp, 0x1000 
ori $gp, $gp,0x8000 

lwc1 $f16, 0($gp)     #load number 5 to f16 

cvt.s.w $f16, $f16    #convert to float 

lwc1 $f18, 4($gp)     #load number 9 to f18 

cvt.s.w $f18, $f18    #convert to float 

div.s $f20 , $f18,$f16   #save number 9/5(f18/f16) to f20 

lwc1 $f14, 8($gp)     #load number 32 to f14 

cvt.s.w $f14 $f14     #convert to float 

li  $v0,6      #read from user 
mov.s $f12,$f0 

mul.s $f0,$f12,$f20    #Celsius * 9/5 
add.s $f0,$f0,$f14    #(Celsius*9/5)+32 

li $v0,4 
la $a0,message3 
syscall       #Type the Result! 

mov.s $f12,$f0 
li  $v0,2 
syscall 

jr $ra 
+0

hey da Kintzo, ich bin von auth. Danke für Ihre Hilfe. Ich hatte meinen Code schon gemacht, er ist sehr ähnlich mit Ihrem, aber ich habe zwei Funktionen, checke meinen Code aus und sage meinem, wenn du deine Meinung willst. Außerdem hast du $ ra benutzt (zurück von der Funktion), ohne tatsächlich anzurufen via $ jal. Das ist ein Problem, das von Craig erwähnt wurde. Hier ist mein Code –

0

@kintzo hey es Kintzo, ich bin von Auth. Danke für Ihre Hilfe. Ich hatte meinen Code schon gemacht, er ist sehr ähnlich mit Ihrem, aber ich habe zwei Funktionen, checke meinen Code aus und sage meinem, wenn du deine Meinung willst. Außerdem hast du $ ra benutzt (zurück von der Funktion), ohne tatsächlich anzurufen via $ jal. Das ist ein Problem, das Craig erwähnt hat.Hier ist mein Code

.data 0x10008000 
    .word  5,9,32 



msg_scale: .asciiz  "Select the temperature scale:<C or F><ENTER>" 
msg_temp: .asciiz  "Type the desired temperature <ENTER>" 
msg_out: .asciiz  "Temperature= " 
msg_nl:  .asciiz  "\n" 

    .text 

    .globl main 

main: 
    # prompt user for temp type/scale 
    li  $v0,4 
    la  $a0,msg_scale 
    syscall 






    # read in temp scale 
    li  $v0,12 
    syscall 
    move $t0,$v0 

    # output a newline 
    la  $a0,msg_nl 
    li  $v0,4 
    syscall 

    # prompt for temperature 
    li  $v0,4 
    la  $a0,msg_temp 
    syscall 

    # read in temperature 
    # NOTE: result comes back in $f0 and _not_ $v0 
    li  $v0,6 
    syscall 



    li  $t1,'F' 
    beq  $t0,$t1,F 


    li  $t1,'C' 
    beq  $t0,$t1,C 

F: 
     jal Farenheit 

    la  $a0,msg_out 
    li  $v0,4 
    syscall 

    mov.s $f12,$f0 
    li  $v0,2 
    syscall 

    la  $a0,msg_nl 
    li  $v0,4 
    syscall 


    j  main_exit 


C: 
     jal Celcius 


    la  $a0,msg_out 
    li  $v0,4 
    syscall 

    mov.s $f12,$f0 
    li  $v0,2 
    syscall 

    la  $a0,msg_nl 
    li  $v0,4 
    syscall 


j  main_exit 



main_exit: 
    li  $v0,10 
    syscall 





    .globl Farenheit 

    Farenheit: 

    lui $gp , 0x1000 
    ori $gp , $gp, 0x8000 

    lwc1 $f16 , 0($gp) 

    cvt.s.w $f16,$f16 

    lwc1 $f18, 4($gp) 

    cvt.s.w $f18, $f18 

    lwc1 $f14, 8($gp) 

    cvt.s.w $f14 $f14 

    div.s $f20,$f16,$f18   # get 5/9 
    mov.s $f12,$f0 
    sub.s $f12,$f12,$f14   # subtract 32 from given temprerature 
    mul.s $f0,$f20,$f12   # multiply by 5/9 
    jr  $ra 







.globl Celcius 

    Celcius: 

    lui $gp , 0x1000 
    ori $gp , $gp, 0x8000 

    lwc1 $f16 , 0($gp) 

    cvt.s.w $f16,$f16 

    lwc1 $f18, 4($gp) 

    cvt.s.w $f18, $f18 

    lwc1 $f14, 8($gp) 

    cvt.s.w $f14 $f14 


    div.s $f20,$f18,$f16   # get 9/5 
    mov.s $f12,$f0 
    mul.s $f12,$f12,$f20   # multiply by 9/5 
    add.s $f0,$f12,$f14   # add 32 
    jr  $ra 
+0

Dies scheint eine Antwort auf @ Kinto zu sein, aber anscheinend ist es auch eine Antwort auf Ihre eigene Frage, da Sie sagen, dass dieser Code richtig funktioniert. Es wäre besser, dies als eine richtige Standalone-Antwort zu veröffentlichen, und einen Kommentar zu Kintos Antwort zu hinterlassen, um ihn wissen zu lassen, dass Sie das gepostet haben. (Eine Diskussion im Text Ihrer Antwort ist nicht, wie wir Dinge auf SO tun). –