views:

34

answers:

2

If I have a value in an "f" register in MIPS, how do I truncate this down to X.YZ from X.YZDEF? Supposedly, you must convert from the float to two ints and display those... How is this done?

+1  A: 

You may want to look and see if these links will help you.

http://en.wikipedia.org/wiki/MIPS_architecture#MIPS_Assembly_Language

http://chortle.ccsu.edu/AssemblyTutorial/index.html#part8

You may also find this helpful: http://www.uni-koblenz.de/~avolk/MIPS/Material/MIPSFloatingPointInstructions.pdf

It has been a long time since I did assembly programming, but, if you multiply by 100 <mul.s>, then you will copy the number to an integer register, then if you divide by 100 <div> then you will have just the two digits on the right. The number to the left of the decimal will be in LO and the number to the right should be in HI, I expect.

James Black
Hmm, that makes sense, except when you do mul.s, you need to put it in an "f" register.
Roger
Right, you will do mul.s, then copy that result to an integer register, then do the division.
James Black
Ahh I see...Thanks, Gunna try that and then I'll comment and let you know how it goes. Thanks James.
Roger
how do you suggest I copy to an int register?
Roger
Ahh, I figured that out. I realized something though...if you multiply on a calculator, for example 5.59 x 2.719, I get 15.2261281. That means the answer should be 15.23, rounded. When I use your method, I get 15.22. Is there a way to round this instead of truncate? Maybe I should have used the word "round" instead of truncate.
Roger
+1  A: 

The easiest thing to do is:

  1. multiply the value by 100 (mul.d),
  2. round to an integer, (round.l.d),
  3. convert back to floating point (cvt.d.l), and
  4. divide by 100 (div.d).
Gabe