CMPS-2240 Lab 5
Read a file, parse numbers, do arithmetic

Gordon Griesel
Department of Computer and Electrical Engineering and Computer Science
California State University, Bakersfield

Two files to be submitted:
lab5.s
lab5a.s

Part 1: Read a file and stop

We worked on this together in lab class.

The file we wrote, lab5.s, is now available in a working form.
The new file is named: lab5a.s

Get a copy of the file here:
/home/fac/gordon/public_html/2240/code/lab5/lab5a.s

Do not overwrite your own lab5.s program.

Do your work for this lab in the lab5a.s program you are given.

What to do...

1. Run the program.
   Make sure the program reads your local myfile.txt file.

2. The program will parse each word or number.
   If your text file contains any numbers,
       accumulate the total sum of all the numbers in your file.

3. When you get the program working, remove the debug output.
   Note: Use comments to stop the debug output.
         Do not remove all the debug code, just comment it out.
         -or-
         Use jump (j) statements to jump around the debug output.

4. Add an option to the program...
   Allow the user to specify the text filename on the command-line.

5. Check for error when opening the file.
   Print a message showing "File open error!" or something similar.

There are several correct ways to get this program done.

sample output:


$ spim -f lab5a.s

Total of numbers is: 635

For a higher score, do one of these output formats:


$ spim -f lab5a.s

123 456 2 9 45
sum: 635 


$ spim -f lab5a.s lab5a.txt

123 + 456 + 2 + 9 + 45 = 635 


$ spim -f lab5a.s myfile.txt

 123
 456
   2
   9
  45
----
 635 

What to turn in

Files on Odin:

   2240/5/lab5.s
   2240/5/lab5a.s
   2240/5/myfile.txt