Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

Describe the linkages between HRM and strategy formulation. page 74

Answered: 1 week ago

Question

Identify approaches to improving retention rates.

Answered: 1 week ago