This part of the assignment consists of writing MIPS assembly language programs and testing them using the MIPS simulator SPIM. You will implement two MIPS programs: iadd (an iterative multiprecision integer addition function) and imultr (a recursive multiprecision integer multiplication function). The SPIM simulator is described in appendix A and can be obtained from www.mkp.com.cod2e.htm (or for the PC version locally at spimwin.exe). Lab 3 provided an introduction to the use of SPIM.
In this assignment students will experiment with multiprecision integer addition and multiplication. Multiprecision integers are usually represented as a sequence of digits stored in an integer arrays. The digits are to a certain base or radix. Usually the radix is large -- close to the largest number that can be represented by the computer word. We will use a small radix -- 10 to make debugging easier. However, you may want to specify the radix in a separate memory location.
The integers are represented as arrays of decimal digits. Specifically, an integer is declared as an integer array of size n+1 or larger. The first element is the size (n) of the integer (i.e, A = n) . The digit at element 1 (A) is the least significant; the last digit at A[n] is the most significant digit. That is if you print the elements out from 1 through n you will get your integer in the reverse order. (Hence, your print function should print the elements in the reverse order.) The integer array will, thus, have n+1 meaningful elements. Therefore, you could declare an array of larger size than the integer that it will actually contain. Hence, you can think of the declared array space as a container for the integer digits.
iadd will take two arrays containing integers encoded as described below and perform a ripple carry addition. (Ripple carry addition is the same as adding two large numbers on paper -- add least significant digits first, if there is a carry, add it to the next column, etc.)
imultr will take two arrays containing integers encoded as described below and perform a recursive multiplication by splitting each integer in half at a certain digit k. Review the following math and observe how integer multiplication can be computed recursively by isolating k least significant digits from each integer and then computing "smaller" multiplication:
A sample C++ code for iterative iadd: iadd.cpp.
A sample C++ code for recursive imultr: imultr.cpp.
A sample C++ code for recursive imultr with random test routine: imultr_random_test.cpp (This is for your reference only!)