Note: Make reasonable assumptions where necessary and clearly state them. Feel free to discuss problems with classmates, but the only written material that you may consult while writing your solutions are the textbook and lecture slides.
For this assignment, you will have to hand all solutions in electronically.
Log in to one of the CADE Lab machines (for example ssh to lab1-10.eng.utah.edu or replace 10 with any number between 1-48). Place your solution
in a text file called "homework3.s" (if you use a different file name, our
print script may not find it -- also, do not include a space in your filename)
and use the following command:
handin cs3810 hw3 homework3.s
Grading: Your program will be graded on readability and user friendliness, as well as correctness. That means LOTS OF COMMENTS!! We won't test it with data that causes overflow, or with non-numerical input data. As with other homework assignments, the TA will print out and test it on a Unix machine in the CADE Lab. You should test your program on that platform before handing it in. The two versions of SPIM (Windows and Unix) are essentially the same, but the text file is the issue. A common problem is that some Windows editors insert strange characters in files, and a Unix machine sometimes doesn't understand them.
Problem description: Given a number N and its square (N^2), the square of N+1 can be computed with the following equation: (N+1)^2 = N^2 + 2*N + 1 = N^2 + N + (N + 1). In other words, you can compute the square of N+1 by adding N and N+1 to the square of N. Your program should have a main routine that (i) prompts the user to enter the values for N and N^2, (ii) reads in these two integer values and confirms they are greater than zero (print an error message and exit if this is not true), (iii) enters a loop that prints the squares of numbers (N+i) from i=1 to i=5. The loop should call a procedure "nextsquare" to implement the math. Procedure nextsquare takes in arguments X and X^2 and returns the value X^2 + X + (X+1).
Here are some examples of how your program should behave:
You may use other subroutines if you wish. If you decide to declare any integer constants or variables in the data section of your program, be sure to put the .word and .space directives before the .asciiz directives. The reason for doing this is that 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. (Another way to do that is to put a ".align 2" command before your .space or .word declarations. See page A-47 for an explanation.) You may assume that we won't test your code with input data that doesn't make sense. It may help you if you write and test your algorithm in a high level language before you start coding it in assembly language.