Question
In MIPS Assembly Language (MARS) Write a program to approximate and return the square root of a number. Create a loop to repeatedly prompt the
In MIPS Assembly Language (MARS)
Write a program to approximate and return the square root of a number. Create a loop to repeatedly prompt the user to enter a real number and calculate and print the square root. Stop prompting when the user enters a negative number.
To calculate the square root we calculate approximations that get successively closer to the actual square root. The calculation stops when the approximation gets "close enough" to the actual value of the square root. The approximation is "close enough" when the difference between the approximation and the actual value is less than some specified value, called the tolerance. The calculation needs three values: num (the number whose square root is being calculated), prev approx (the last approximation to the square root), and tol (the tolerance). The new approximation is calculated using the following formula:
previous approx2 + num new approx = ---------------------- 2 * previous approx
The approximation is "close enough" and can be returned when
|approx2 - num| <= tol
If the approximation is not close enough, make the new approx the previous approx and calculate again. Use the number itself for the initial approximation. Use 0.0001 for the tolerance. (Hint: make the tolerance a variable (using .float) and then load it into a register.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started