Click here to Skip to main content
16,016,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to ask how I can do floor and ceil functions in MIPS assembly??
Posted

1 solution

You should definitely get some copy of the MIPS instruction set reference. Even without that I was able to find the instructions floor.s and ceil.s using Google.

However, these are only supported with newer MIPS CPUs. But you can also do it the hard way by adding or subtracting 0.5 (depening on the sign of the argument and the function) and convert the result to an integer.
[EDIT]
And Google will even find an example for floor: https://github.com/jrvidal/goruden-boi/blob/master/lit/cs61c/floor.s.md[^].
 
Share this answer
 
v2
Comments
amin.j 30-Oct-15 14:02pm    
I used this code but it has error in 4th line:

# y= 0.4*x+1
li.s $f0, 0.4
mul.s $f2, $f0, $f1
floor.w.f $f3, $f2
Jochen Arndt 31-Oct-15 4:47am    
Please read and show the error message. It should give a hint what is wrong.

My guess: The instruction is wrong. I would try floor.w.s.
CPallini 30-Oct-15 14:19pm    
I definitely agree. 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900