MIPS如何将双精度值加载到寄存器中?

MIPS如何将双精度值加载到寄存器中?,mips,Mips,在mips汇编中,有一条指令(addi)将整数值放入寄存器,我的问题是: addi $t1,$zero,8.9 #MIPS ERROR 如果我想在MIPS中的寄存器中放入一个双精度值,我必须使用哪条指令???加载浮点指令最简单的方法是从内存中加载它们 在数据部分,您可以定义浮点常量,例如 .data doubleValue: .double 123.456 floatValue: .float 123.456 然后使用伪指令l.s(用于浮点)和l.d(用于双精度)将它们加载到浮点寄存器上,例

在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

加载浮点指令的最简单方法是从内存中加载它们

在数据部分,您可以定义浮点常量,例如

.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(操作数)而不是$t(操作数)

这些值不能作为立即值加载,它们必须在
.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

它非常类似于写入操作数的搁浅方式。 第一个区别是应该使用$f(操作数)而不是$t(操作数)

这些值不能作为立即值加载,它们必须在
.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

我构建了编译器,所以…很难在(.data)中保存所有的双精度值,如果我使用您的方式,我必须将每个双精度变量与它的值链接起来。。。所以hard@elisha当前位置我不完全理解你的问题。还有另一种(棘手的)方法可以直接加载浮点常量。请参阅更新的答案如果我使用您的(棘手的)方法,我必须计算每个要放入寄存器的双精度值的编码?c/c++中有一个函数可以计算给定双精度值的编码吗@gusbro@elisha:如果使用C,则不需要函数来获取编码,必须将浮点视为整数,例如:
float something=123.456;int编码=*((int*)&something)。您可能会再次看到这个棘手的问题;)我构建了编译器,所以…很难在(.data)中保存所有的双精度值,如果我使用您的方式,我必须将每个双精度变量与它的值链接起来。。。所以hard@elisha当前位置我不完全理解你的问题。还有另一种(棘手的)方法可以直接加载浮点常量。请参阅更新的答案如果我使用您的(棘手的)方法,我必须计算每个要放入寄存器的双精度值的编码?c/c++中有一个函数可以计算给定双精度值的编码吗@gusbro@elisha:如果使用C,则不需要函数来获取编码,必须将浮点视为整数,例如:
float something=123.456;int编码=*((int*)&something)。您可能会再次看到这个棘手的问题;)