MIPS 如何将双精度值加载到寄存器中?
how MIPS load an double value into a register?
在 mips 汇编中有将整数值放入寄存器的指令 (addi),我的问题是:
addi $t1,$zero,8.9 #MIPS ERROR
如果我想将双精度值放入 MIPS 中的寄存器中,我必须使用哪条指令??
加载浮点立即数的最简单方法是从内存中加载它们。
在数据部分你可以定义浮点常量,例如
.data
doubleValue: .double 123.456
floatValue: .float 123.456
然后使用伪指令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
或者,您可以将编码浮点数的立即数加载到通用寄存器中,然后使用 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
如果你要将 123.456 加载到双精度数上,你会发出:
li $t2, 0x1a9fbe77 # 0x405edd2f1a9fbe77 is the encoding for 123.456 double
li $t3, 0x405edd2f
mtc1.d $t2, $f2 # move that double to $f2-$f3
这与操作数的写法非常相似。
第一个区别是应该使用 $f(operand number) 而不是 $t(operand number).
这些值不能作为立即值加载,它们必须在 .data
部分声明。
您使用的浮点寄存器应该是偶数。
然后当您加载浮点值时,操作码应该是 l.s
。
应使用 add.d
命令,因为这些是双精度值
例如添加 10 和 2.5
.data
float1 : .float 2.5 # declaring the floating values
float2 : .float 10.0 # declaring the floating values
.text
main :
l.s $f0 , float1 # loading the floating values to regester
l.s $f2 , float2 # loading the floating values to regester
add.d $f4 , $f0 , $f2
在 mips 汇编中有将整数值放入寄存器的指令 (addi),我的问题是:
addi $t1,$zero,8.9 #MIPS ERROR
如果我想将双精度值放入 MIPS 中的寄存器中,我必须使用哪条指令??
加载浮点立即数的最简单方法是从内存中加载它们。
在数据部分你可以定义浮点常量,例如
.data
doubleValue: .double 123.456
floatValue: .float 123.456
然后使用伪指令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
或者,您可以将编码浮点数的立即数加载到通用寄存器中,然后使用 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
如果你要将 123.456 加载到双精度数上,你会发出:
li $t2, 0x1a9fbe77 # 0x405edd2f1a9fbe77 is the encoding for 123.456 double
li $t3, 0x405edd2f
mtc1.d $t2, $f2 # move that double to $f2-$f3
这与操作数的写法非常相似。 第一个区别是应该使用 $f(operand number) 而不是 $t(operand number).
这些值不能作为立即值加载,它们必须在 .data
部分声明。
您使用的浮点寄存器应该是偶数。
然后当您加载浮点值时,操作码应该是 l.s
。
应使用 add.d
命令,因为这些是双精度值
例如添加 10 和 2.5
.data
float1 : .float 2.5 # declaring the floating values
float2 : .float 10.0 # declaring the floating values
.text
main :
l.s $f0 , float1 # loading the floating values to regester
l.s $f2 , float2 # loading the floating values to regester
add.d $f4 , $f0 , $f2