how do you do a square root in MIPS? I have to write a program to find the hypotenuse of a right triangle and I'm stuck on this part. Please help.
how do you do a square root in MIPS? I have to write a program to find the hypotenuse of a right triangle and I'm stuck on this part. Please help.
> how do you do a square root in MIPS?
Same as anywhere else, assuming you lack a library to do it
- research algorithms (you've got google, do some searches)
- write code
- test code
> how do you do a square root in MIPS?
Same as anywhere else, assuming you lack a library to do it
- research algorithms (you've got google, do some searches)
- write code
- test code
I tried looking for an algorithm to do so. however, the only ones I came upon requires me to split the number being rooted by 2's. Not possible.
> the only ones I came upon requires me to split the number being rooted by 2's. Not possible.
Are there more restrictions on the answer that you're not telling us?
What does "split the number by 2" mean anyway - divide?
not divide by 2 but separate the digits into 2.
example: if the number I want to root is 96358
9, 63, 58 is what i split it into.
> the only ones I came upon requires me to split the number being rooted by 2's. Not possible.
Are there more restrictions on the answer that you're not telling us?What does "split the number by 2" mean anyway - divide?
the instruction just says, find the hypotenuse of 2 user input leg of a right triangle. the 2 input are floating points.
newton's method means i have to use derivative.... according to that formula.
I can't help you any more without giving you the answer on a plate.
What were the rules your teacher gave you?
Which flavor of MIPS are you using?
There are scalar and vector square root functions and estimated reciprocal square root vector functions, dependent upon which MIPS family chipset you're using!
There are also algorithmic guesstimation formulas for integer only processors.
What were the rules your teacher gave you?
Which flavor of MIPS are you using?There are scalar and vector square root functions and estimated reciprocal square root vector functions, dependent upon which MIPS family chipset you're using!
There are also algorithmic guesstimation formulas for integer only processors.
there are different MIPS?
here is the program i'm working on. hopefully you can determine what flavor it is by looking at it because I'm clueless.
#stuck, cannot figure out square root
.text
.globl __start
__start:
la $a0, prompt #print the directions to screen
li $v0,4
la $a0,prompt # prompt user for a
li $v0,4 # print string
syscall
li $v0,6 # read single
syscall # x stored to f0
mov.s $f2,$f0
la $a0,prompt2 # prompt user for b
li $v0,4 # print string
syscall
li $v0,6 # read single
syscall
# evaluate a and b to get c
mul.s $f2,$f2,$f2 # square a
mul.s $f0,$f0,$f0 # square b
add.s $f2,$f2,$f0 # add a^2 and b^2
# print the result
mov.s $f12,$f2 # $f12 = argument
li $v0,2 # print single
syscall
la $a0,newl # new line
li $v0,4 # print string
syscall
li $v0,10 # code 10 == exit
syscall # Return
## Data Segment
.data
pi: .float 3.14
degree: .float 180.0
prompt: .asciiz "Enter a: "
prompt2:.asciiz "Enter b: "
blank: .asciiz " "
newl: .asciiz "\n"
I used the word 'flavor' but that's one of my descriptive words like 'squirelly'. "The code is acting squirelly!" There are many MIPS architectures and cores within the MIPS family.
Visit www.mips.com are review the Cores and Architectures.
The processor is designed for co-processors to be plugged in like building blocks. I'm over simplifying the mechanism but read their documents.
That code isn't really going to help as I doubt you're using 3D instructions yet, or SIMD, etc. Are you using a MIPS simulator or a prototyping board, or a custom design? What model processor does it use?
I believe the MIPS 3000 didn't have a square root function. It had basic Single/Double-Precision functionality. +-*/
SQRT.S fd,fs MIPS II Square Root
SQRT.D fd,fs
fd = sqrt( fs )
RSQRT.S fd,fs MIPS IV Estimated reciprocal square root
RSQRT.D fd,fs
fd = 1 / sqrt( fs )
and to get it to square root
fe = fs * fd