Integer Addition and Multiplication 

CS 281 Systems Architecture I

Overview

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.

Description

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[0] = n) . The digit at element 1 (A[1]) 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!)

What to do

  1. Review the sample C++ code above. You should generally follow the C++ code while writing your MIPS code.
  2. iadd: Write iadd function in MIPS. Write a MIPS Print function that prints out the integer to console one digit at a time using syscall. Declare three arrays -- two with defined integers in them and one for the result. Finally, write a main that calls Print on the two integers, calls iadd and then call Print on the result. Test each subfunction thoroughly before proceeding. 
  3. imultr: Write recursive multiplication function in MIPS. Write a MIPS Print function that prints out the integer to console one digit at a time using syscall. Declare three arrays -- two with defined integers in them and one for the result. Finally, write a main that calls Print on the two integers, calls imultr and then call Print on the result. Test each subfunction thoroughly before proceeding. (You do not have to replicate my random test version. I have provided it for extra reference.)
  4. Test/run your programs in SPIM. There should not be user input to your program; instead you should define the array and its size via .word directives. There must be a reasonably nice output to the console, however. Please review Lab 4 for more information and help.
  5. Note: graders are instructed to take at least 25% off your grade if your program does not work as expected.

What to hand in for Part II

  1. A separate description file should summarize what you did: summarize code you wrote, experiments performed, and files included, etc. Please follow my specifications for a description file.
  2. Documented MIPS source code for iadd and imultr programs. Please follow the specifications above and in the C++ code provided. Each function must have input and output specifications.
  3. A copy of the console output from executing both of your main programs.