该程序 MIPS(double) 的输出有问题

There is something wrong with the output of this program MIPS(double)

我正在用 MIPS 编写程序将英寸转换为厘米,但结果总是计算为 零。我不知道我哪里做错了。我写了下面的程序。它正在编译,但没有评估正确的结果,总是给出 0。

#declaring some things

.data
    inchesText: .asciiz "Enter the number in inches: "
    resultText: .asciiz " Centimeters are ==> "
    inches: .double 0
    inchesToCenti: .double 2.54
    centi: .double 0
    zero: .word 0
    result: .double 0
.text

main:
    jal getInches
    jal inches_To_Centi
    jal finalResult

    jal Exit
getInches:
    # printing string
    la $a0,inchesText
    li $v0, 4
    syscall
    # get inches
    li $v0, 7
    syscall
    s.d $f2, inches
    jr $ra

inches_To_Centi:

    # loading the formula contstant as it is
    l.d $f0, inchesToCenti

    #actual inches gained through argument
    l.d $f2, inches

    # mul both of these to get the centimeters
    mul.d $f6, $f0, $f2
    s.d $f6, centi

    jr $ra

finalResult:
    # printing text
    la $a0, resultText
    li $v0, 4
    syscall

    # now printing the actual value
    l.d $f12, centi
    li $v0, 3
    syscall

Exit:
    li $v0, 10
    syscall

是不是有很多时间我不这样做assemble但我认为你的问题的解决方案是关于你用来读取双精度值的系统调用。

syscall 7不将输入值存入$f2寄存器,而是存入$f0寄存器。

将第 26 行更改为

s.d $f0 inches 

为了提供更多上下文,由于行号不存在,getInches 子例程需要修复:

getInches:
    # printing string
    la $a0,inchesText
    li $v0, 4
    syscall
    # get inches
    li $v0, 7
    syscall
    s.d $f0, inches
    jr $ra