0 mips
在 mips 汇编中有指令(addi)将整数值放入寄存器,我的问题是:
addi $t1,$zero,8.9 #MIPS ERROR
Run Code Online (Sandbox Code Playgroud)
如果我想将双精度值放入 MIPS 中的寄存器中,我必须使用哪条指令?
加载浮点立即数的最简单方法是从内存加载它们。
在数据部分您可以定义浮点常量,例如
.data
doubleValue: .double 123.456
floatValue: .float 123.456
Run Code Online (Sandbox Code Playgroud)
然后使用伪指令l.s(对于浮点数)和l.d(对于双精度数)将它们加载到浮点寄存器中。例如
.text
l.s $f1, floatValue # Loads constant 123.456 onto $f1
l.d $f2, doubleValue # Loads constant 123.456 onto $f2-$f3
Run Code Online (Sandbox Code Playgroud)
或者,您可以将编码浮点数的立即数加载到通用寄存器中,然后使用mtc1/mtc1.d将它们移动到浮点寄存器。从必须对浮点常量进行编码的意义上来说,这是很棘手的。
例如,假设您想将 123.456 加载到浮点寄存器中,您可以这样做:
li $t1, 0x42f6e979 # 0x42f6e979 is the encoding for 123.456 single precision float
mtc1 $t1, $f1 # move that float to $f1
Run Code Online (Sandbox Code Playgroud)
如果您要将 123.456 加载到 double 上,您将发出:
li $t2, 0x1a9fbe77 # 0x405edd2f1a9fbe77 is the encoding for 123.456 double
li $t3, 0x405edd2f
mtc1.d $t2, $f2 # move that double to $f2-$f3
Run Code Online (Sandbox Code Playgroud)