Labatory 1: Basic SPIM This is an ungraded programming assignment -- see syllabus for information on how it will be counted. You need to have the assignment checked off by your lab supervisor (or at least some of it), and then you should electronically hand it in by Tuesday January 19th at 9pm. As mentioned in class, the M and T sessions are optional, while the W and Th sessions are required. This week, the TAs will introduce you to using SPIM on W and Th. The sessions are: MW 9:00-11:00AM David Dahle MW 7:15- 9:15PM Huabo Chen TTh 10:00-12:00PM Kevin Delaney TTH 6:00- 8:00PM David Dahle TTH 2:00- 4:00PM Huabo Chen The purpose of the first programming assignment is to familiarize yourself with SAL and SPIM. The constructs used in this program are quite basic, and you should be able to directly use your if, while, and for loops from the notes. Be sure to comment your code nicely! Note that when running a SAL program in SPIM/SAL, the program is translated into full MIPS assembly language, and then run, so that in the simulation, you'll see more instructions executing than you might expect. To run SPIM, execute the following command at the UNIX prompt: % xspimsal -file where is the name of the file containing your SAL program. SPIM is an interpreter, so there is no compilation step. 0. The file /cats/cmpe12c/examples/printx.spim contains a program from Chapter 2 that prompts for an interger and then prints an X the corresponding number of times. Copy this program to your home directory and try running it in SPIM. Try running the program with the run button, and single stepping through the program with the step button. Notice you will need to step several times for each SAL instruction, since SPIM executes the the lower level TAL instructions, not the SAL instructions. When SPIM beeps at you when stepping, it is probably waiting for a response to a "get" instruction. 1. Write a program to (Modify the printx.spim program to): - Prompt the user for a character - Read the character - Add 1 to the character - Print out the character - Exit. 2. Add a control structure - Turn the character into upper case: If it is >= 'a' and <= 'z', add/subtract the appropriate amount (see p 102). WARNING: If you add/subtract the wrong value, you may create an unprintable character, in which case the "put" instruction won't print anything. - print out character - exit 3. Use a procedure call with la - Make the capitalization routine a procedure. 4. Add a for loop - Call the capitalization procedure 10 times from within a for loop. (not 9 or 11!) 5. Change to a while loop - Call the capitalization procedure from a while loop that repeats until a '\n' is entered. Questions: a. It might be nice to have a program that reads in a line of text, capitalizes that, and prints it out (well, for someone!). Why wasn't this assigned? b. What are your initial thoughts on SAL and SPIM? Turn in the following files using the submit command: for.spim (Program 4) while.spim (Program 5) README (Comments about the two programs, and answers to the two questions). % submit cmpe12c prog1 for.spim while.spim README To see check what you've submitted: % peek cmpe12c prog1