2016-05-25 1 views
0

Ich habe diesen Code:Wie wird ein Integer-Wert in ein Doppelregister in MIPS geladen?

void test(int x) 
{ 
    cout<<x; 
    double y=x+4.0; 
    cout<<y; 
} 
void main() 
{ 
    test(7); // call the test in main 
} 

In MIPS: nachdem ich den Wert des Parameters x in 0 ($ fp) in Stapel gelegt und zum Test springen:

lw $a0,0($fp) // load value of x and print it 
li $v0,1  
syscall 

lw $t1,0($fp) 
sw $t1,0($sp) // put the value of x in stack and point it by $sp 

li.d $f0,4.0 
s.d $f0,4($sp) // put the value 4.0 in stack and point it by $sp 

l.d $f0,0($sp) 
l.d $f2,4($sp) 
add.d $f4,$f0,$f2 

s.d $f4,8($sp) // put the result of add 

l.d $f12,8($sp) // print the value of y 
li $v0,3 
syscall 

Mein Problem ist, das Ergebnis von y in QTSPIM ist 4 .... das Problem, weil ich einen ganzzahligen Wert in einem Doppelregister laden ... Wie kann ich dieses Problem lösen ???

Antwort

1

Sie müssen den ganzzahligen Wert in ein fp-Register laden und dann in Gleitkommaformat konvertieren. Sie haben eine 8-Byte-Ladung (die die 4 Bytes Ihres Wertes laden wird, plus die folgenden 4 Bytes, was auch immer sie sind), also möchten Sie wahrscheinlich das ändern und dann eine cvt:

l.w $f0,0($fp) 
cvt.d.w $f0,$f0 
+0

wie du gesagt hast ... es funktioniert dank @Chris Dodd – sam

Verwandte Themen