Question

In: Computer Science

Write MIPS code for finding the (estimated) square-root of a number N, by using the following...

  1. Write MIPS code for finding the (estimated) square-root of a number N, by using the following pseudo-code:

        sqrt = N;
        repeat 10 times {
    
            sqrt = (sqrt + N/sqrt)/2;
        }
    

    The number N is entered by the user and the answer is displayed on the screen as (for example):

                            The square root of 121 is 11.
    
  2. Write MIPS code for finding the distance between two points [x1,y1] and [x2,y2]. The formula for the distance is:

    z = ?(x2 − x1)2 + (y2 − y1)2
    x1,x2,y1 and y2 are entered by the user and the answer z is displayed on the screen as

    (for example):

                                 The distance is 12.
    

    (Hint: Reuse the square-root code from the previous question.

  3. Write MIPS code that finds and prints the smallest number in the integer array “arr”. The declaration of the array is shown below:

      .data
          arr: .word 100, 10, 3, -2, 110, 0, -50, 150, -17, 8
    

Solutions

Expert Solution


Related Solutions

write a function to determine the square root of a number. The square root of a...
write a function to determine the square root of a number. The square root of a number can be approximated by repeated calculation using the formula NG = 0.5(LG + N/LG) where NG stands for the next guess and LG stands for the last guess. The loop should repeat until the difference between NG and LG is less than 0.00001. Use an initial guess of 1.0. Write a driver program to test your square root function. I WANT THIS PROGRAM...
The n th Triangle Problem Write a code for finding the n th triangle number of...
The n th Triangle Problem Write a code for finding the n th triangle number of triangle sequences: 1, 3, 6, 10, ..., n. That is, your code should accept an integer number, which indicates the triangle levels, and returns how many dots we need to form a triangle with respect to the given level. For example, consider the Fig 1. For n = 3 (can be also written as T3), your code should returns 6. Provide a single program...
Write a MIPS assembly language to transpose a square integer matrix in code
Write a MIPS assembly language to transpose a square integer matrix in code
Check a number if the Database. Write MIPS assembly code for the following requirements. Given the...
Check a number if the Database. Write MIPS assembly code for the following requirements. Given the following code for the data segment. .data Database: .word 1,2,3,4,5,6,7,8,9,10 Ask user to type in a random integer number using syscall #5. Check if this number is within the database or not, print out "number found!" if the number was foudn in the database, print out "No such number found in database!" if not.
Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive number n is as follows:
Chapter 3 Exercise 1Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive number n is as follows:      1. Make a guess at the answer (you can pick n/2 as your initial guess).      2. Computer = n / guess.      3. Set guess = (guess +r) / 2.      4. Go back to step 2 until the last two guess values are within 1% of each other.Write a program that inputs an integer for n, iterates through the Babylonian algorithm until the guess...
mips code for n queen problem
mips code for n queen problem
Translate following pseudo-code to MIPS assembly language cout << “\n Please input a number for $s0”;...
Translate following pseudo-code to MIPS assembly language cout << “\n Please input a number for $s0”; cin >> $s0; cout << “\n Please input a number for $s1”; cin >> $s1; cout << “\n Please input a number for $s2”; cin >> $s2; $t0 = $s0 / 8 - 2 * $s1 + $s2; cout << “\n the Value of the expression “$s0 / 8 - 2 * $s1 + $s2” is ”; cout >> $t0; return;
Write code in MIPS ,read tow number from the user that do the following: 1- multiply...
Write code in MIPS ,read tow number from the user that do the following: 1- multiply 2- Dividing 3- sum 4- average 5- minimum 6- maximum 7- print message to thank the user for using my program
I'm writing a code for the Secant Method for root finding, but my code makes an...
I'm writing a code for the Secant Method for root finding, but my code makes an infinite code of the correct answer. Below is my code, how do I fix it? def f(x): return (x**6)+7*(x**5)-15*(x**4)-70*(x**3)+75*(x**2)+175*x-125 def secant(): p0=float(input('Enter an initial guess for the root ')) p1=float(input('Enter another guess ')) TOL=float(input('Enter a tolerance in decimal form ')) n=15 i=1 while i<=n: p=p1-f(p1)*(p1-p0)/(f(p1)-f(p0)) if abs(p-p1)<TOL: print(p) else: p0=p1 p1=p i=i+1 else: print(p) return p    print(secant())
Write a program using the following root-finding methods: Mullers Method Use your programs to find approximations...
Write a program using the following root-finding methods: Mullers Method Use your programs to find approximations to within 10^(-4) to all zeros of the following cubic polynomials. Use |P_(n+1)-P_n| as a measure of the error in the iteration. Save all of the iterations. What are your conclusions? (a) f(x) = x^3-5x^2 + 2x (b) f(x) = x^3-2x^2-5 The program has to be used with MATLAB. I'm still learning how to use the program. I would love some help and tips...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT