Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your code must approximate the square root of an integer between 0 and 2^31-1 Using integer maths is sufficient (no floating point or fractions are

Your code must approximate the square root of an integer between 0 and 2^31-1 Using integer maths is sufficient (no floating point or fractions are required); your code will return the truncated (integer portion) of the square root. Your code must be in an assembly language subroutine which is called by a C function for testing. Be sure to use registers according to the ARM calling convention.

Base your software on the following pseudocode:

Approximate square root with bisection method INPUT: Argument x, endpoint values a, b, such that a < b OUTPUT: value which differs from sqrt(x) by less than 1

done = 0 a=0 b = square root of largest possible argument (e.g. ~216). c = -1 do {

c_old <- c c <- (a+b)/2 if (c*c == x) {

 done = 1 } else if (c*c < x) { 

a <- c } else {

b <- c

} } while (!done) && (c != c_old)

return c

Write an assembly code subroutine to approximate the square root of an argument using the bisection method. All math is done with integers, so the resulting square root will also be an integer

GOOD LUCK! *----------------------------------------------------------------------------*/

__asm int my_sqrt(int x){ //Write your code here

}

/*---------------------------------------------------------------------------- MAIN function *----------------------------------------------------------------------------*/ int main(void){ volatile int r, j=0; int i; r = my_sqrt(0); // should be 0 r = my_sqrt(25); // should be 5 r = my_sqrt(133); // should be 11 for (i=0; i<10000; i++){ r = my_sqrt(i); j+=r; } while(1) ; }

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

More Books

Students also viewed these Databases questions

Question

4. examine the process of psychological self-regulation,

Answered: 1 week ago

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago