4

I cannot use li.s in MARS. I am new to MIPS programming and I am trying not to use any co processors. Why can I not use li.s is MARS the program? It would be very helpful is someone could lead me in a new direction!

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107

2 Answers2

2

It is a pseudoinstruction, which is probably not implemented in mars. You can use sequence of li (ori) and mtc1.

This loads the value 1.234 to $fp1 and works in MARS:

li $t1,0x3f9df3b6
mtc1 $t1,$f1

the hexadecimal or integer value can be found using http://babbage.cs.qc.edu/IEEE-754/Decimal.html or using a simple program (in Fortran, in C is similar using a pointer cast):

read(*,*) a
i=transfer(a,i)
write(*,*) i
end
1

You can achieve the same effect as the pseudoinstruction li.s using pseudoinstruction l.s and the constant stored in the data segment:

  l.s $f1, fpconst

.data 0x1000
fpconst:
.float 1.2345

That will use the coprocessor register $f1 to store the floating point constant.

You can also put the constant in a regular register using lw $f1, fpconst instead of l.s

gusbro
  • 22,357
  • 35
  • 46
  • But that changes the meaning slightly and introduces the cost of loading the value from the main memory via the FSB. – Vladimir F Героям слава Nov 10 '11 at 16:09
  • Pseudoinstruction li.s does exactly what I've written. Check the book [MIPS Assembly Language Programmer's Guide](http://www.cs.unibo.it/~solmi/teaching/.../AssemblyLanguageProgDoc.pdf), page 9-21 – gusbro Nov 10 '11 at 16:28
  • And I agree with you. It loads a value from an address, i.e. from memory. From the place in memory you declaredin .data segment. But that costs something, if it's a chache miss, it can cost much more, than li. – Vladimir F Героям слава Nov 10 '11 at 16:33
  • Well, I guess it might cost more but it might also cost less, you'd have to check on a case-by-case basis. – gusbro Nov 10 '11 at 16:42
  • Is there a difference between l.s and lw? –  Nov 10 '11 at 17:24
  • Yes. `l.s` is a pseudoinstruction (basically lwc1) that loads a constant from memory to a coprocessor register, whereas lw is just a standard instruction that loads a constant from memory to a regular CPU register. – gusbro Nov 10 '11 at 17:31