Programming Assignment 3: Computing Sums

Due Thursday, October 18
15 points


Introduction

For this assignment write a MAL program that returns the sum of integers from 1 to n, where n is entered by the user. The program should continue to prompt for n and display the sum as long as the user enters a positive number. When the user enters 0 or a negative integer, the program should not print the sum. Instead, it should print a message indicating that the program is terminating.

Writing the program

You should read the web page Using SPIM and XSPIM before attempting this lab.

To begin with, create a file containing the code in sums.s using the UNIX editor of your choice. Take care to enter the code correctly. It is difficult to locate errors until you have acquired more experience.

The program in sums.s just prompts the user for a single integer n and displays the sum of integers from 1 to n. Run the program several times using xspim. See Assembling and Running MAL Programs with XSPIM for instructions on the use of xspim.

When you are comfortable with xspim, edit the sums.s file to add an outer loop that repeats the prompting, getting n, and displaying the sum. You may want to keep xspim running, opening another xterm window to do editing. Be sure to save changes before clearing, loading, and running in xspim. Test the sums program using the xspim program, entering various numbers until you are sure that it is running correctly.

What to hand in

Turn in a typescript showing the contents of your final version of sums.s and a spim session with the following user inputs:

For making typescript, you should run spim rather than xspim. See Assembling and Running MAL Programs with SPIM for instructions on the use of spim.