MIPS has special commands and registers for working with real numbers. For example, this command works with integers:

add $s0, $s0, $s1 

It writes to the $ s0 register the sum of $ s0 and $ s1. To work with real you need to write this:

 add.d $f0, $f0, $f1 

Registers starting with f are just registers for real numbers. If in the last command you specify registers that begin with no f - that is, regular registers - then there will be a compilation error.

For integers there is also such a command:

 addi $s0, $s0, 10 

It writes in $ s0 the sum of $ s0 and 10. That is, at the beginning, when in all registers zero it can be used to write some values ​​to the registers, and only then work with them. But there is no analogue of this command for real numbers. It turns out a strange situation there are commands and registers for real numbers, but in these registers is always zero. Please tell me how to write values ​​in them?

1 answer 1

In MIPS, there are li.s and ld instructions for this. The first initializes the register with the immediate operand; the second takes the value from memory. For example:

 .data val: .double 1.0 .text li.s $f1, 1.0 ld $f2, val