MIPS 将浮点数转换为整数

MIPS convert float into an integer

我试过用几种不同的方式来看待它,其中一种是使用二进制进行移位 left/right 但我只是无法找到一种组合来使其适用于除少数之外的任何东西每次选择号码。那么如何将浮点数转换为整数呢?

.data
five: .float 10.0

.text

main:
    la  $a1 five 
    l.s $f12 ($a1) 
    #conversion here

    li $v0 2# print float, which will print 10.0 (should print integer)
    syscall

    li $v0 10
    syscall

免责声明:我不是 MIPS 架构方面的专家。

如评论中所建议,快速查找 MIPS FP 参考 给出了所需的指令:cvt.w.s

.data
    five: .float 5.0
.text

#Convert five into an integer
la $t1, five
l.s $f12, ($t1)             #f12 = five
cvt.w.s $f0, $f12           #f0 = (int) five


#Print five
li $v0, 2
syscall

#Print (int)five
li $v0, 1
mfc1 $a0, $f0               #a0 = (int)five
syscall

#Exit
li $v0, 10
syscall

这将打印

5.05

因为5.05之间没有space。

如果想亲手做,可以从这里开始answer