You are on page 1of 2

Programming Assignment: MIPS Program

Due - Wed Oct 20, 2010(in class)

Total Points 50

Objective

Given a number N and N 2 , the ( N 1) 2 can be computed with the following equation:
( N 1) 2 N 2 2* N 1 N 2 N ( N 1) . Write a MIPS program, which contains a
main routine that will

(i) Prompt the user to enter the values for N and N 2 ,


(ii) Reads the above two integer values and checks if they are greater than
zero. If they are not greater than zero, print an error message and exit the
program,
(iii) Enter a loop that prints the squares of numbers (N+i) from i=1 to i=5. The
loop should call a subroutine nextsquare to implement the mathematical
calculations. Subroutine nextsquare takes in arguments X and X 2 and
returns the value X 2 X ( X 1) .

Program Output

Following are typical examples of output for your program:

o If the user provides inputs to your program as 2 4, then output should be:
Enter N and N^2 (both positive):
2
4
Next 5 squares are: 9 16 25 36 49
o If the user provides incorrect inputs to your program. For example -3 9, the output
should be:
Enter N and N^2 (both positive):
-3
9
The input is incorrect.

Hints and Tips

You are free to use any number of subroutines if you wish. To declare any integer
constants or variables in the data section of your program, remember to put the .word and
.space directives before the .asciiz directives. We need to do this as strings are generally
not multiples of 4 bytes in length. Hence, the memory allocated for them may not end on
a word boundary. If you put .word or .space directives after strings, the assembler may
complain that you are trying to allocate memory for word-length data (i.e., integers) on a
non-word boundary. During testing of your program, I will only enter input data to
contain positive or negative integers. Please write and test your algorithm in a high level
language like C, C++ or Java, before you start coding it in assembly language.

Resources

Tutorial on using SPIM (Appendix A of the text).


Manual on basic SPIM commands.
Another SPIM manual with useful code examples.
A sample skeleton program that you may use as a starting point.

Deliverables

For this assignment, you will have to hand your solution electronically. Please email your
solution containing the MIPS program "MIPSProgram_yourname.s".

Grading

Your program will be graded on readability and user friendliness, as well as correctness.
Please provide adequate comments. The program will not be tested with data that causes
overflow, or with non-numerical input data.

You might also like