CS 210 PROJECT #4 Due: Noon Thursday 04/24/2008 This project offers the student some experience with mixed-language programming, and with using integer arithmetic instructions to calculate square-roots and format numeral-strings representing decimal-fractions. PROBLEM STATEMENT The accompanying application-program named 'sqroots.cpp' calculates and displays a mathematical table of square-roots to four-place accuracy for the positive integers up to one hundred, but it relies upon calls to to a subroutine named 'int2root()' which uses the 'sqrt()' function from the C/C++ math library. That function is implemented by using floating- point operations and data-types which we have not yet studied. In fact, those floating-point operations are not strictly necessary. There is an alternative way to compute square-roots using only integer instructions, based on the well-known recursive identity from high school algebra: (n + 1)*(n + 1) = n*n + (n + n + 1) Thus any positive integer which is a perfect square can be built up just by adding together successive odd integers. The number of summands will then give the square root. EXAMPLE: Compute the square-root of one-hundred The answer is ten, because ten successive odd integers can be subtracted from one hundred (100 = 1 + 3 + 5 + 7 + 9 + 11 + 13 + 15 + 17 + 19), and square-roots for integers which are not perfect squares can be obtained, approximately, using interpolations, as in the following algorithm: // Find sqrt(N) to two decimal-places int product = N * 10000; int nextodd = 1; int counter = 0; char rootbuf[ 20 ]; while ( product > counter ) { product -= nextodd; nextodd += 2; ++counter; } int len = sprintf( rootbuf, " %d", count ); memcpy( rootbuf, rootbuf+1, len-3 ); memset( rootbuf+len-3, '.', 1 ); printf( " square-root of %d equals %s \n", N, rootbuf ); Your job in this assignment is to re-implement the function 'int2root()' as an 'external' subroutine, written in assembly language, and using the CPU's integer operations instead of floating-point aritmetic. Then link your assembly language subroutine to our 'sqroots.cpp' application. You should turn in a printout of your two source-files, and also should copy all of your project's files to your '/submit' direectory. ________________________________________________________________________ Allan B. Cruse University of San Francisco Spring 2008