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?
views:
34answers:
2
+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
2010-04-06 01:10:32
Hmm, that makes sense, except when you do mul.s, you need to put it in an "f" register.
Roger
2010-04-06 01:19:22
Right, you will do mul.s, then copy that result to an integer register, then do the division.
James Black
2010-04-06 01:22:06
Ahh I see...Thanks, Gunna try that and then I'll comment and let you know how it goes. Thanks James.
Roger
2010-04-06 01:23:30
how do you suggest I copy to an int register?
Roger
2010-04-06 01:36:07
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
2010-04-06 01:42:13
+1
A:
The easiest thing to do is:
- multiply the value by 100 (
mul.d
), - round to an integer, (
round.l.d
), - convert back to floating point (
cvt.d.l
), and - divide by 100 (
div.d
).
Gabe
2010-04-06 01:58:14