Lab 1 is due Monday, September 13th. Be prepared to explain your debugging techniques to your TA during section. Your lab report must be submitted by 11:59pm (Monday night) using the submit program (see below).
This lab is to be done individually. Get started early!
Lab Policy: Labs (including final reports) must be submitted by 11:59pm on the day that the lab is due. To submit your lab report, run m:\bin\submit-fall2004.exe or at command prompt, type "submit-fall2004" then follow the instructions. Make sure you input the correct section number, group name (for lab 2-4 and final project), and directory to submit. Otherwise your lab/project grade will NOT be correctly recorded. The required format for lab reports is shown on the handouts page.
Remember, this lab is to be done individually. Get started early!
The software for this assignment is located in m:\bin and m:\lab1. The broken version of spim is called spim_broken. The good version is called spim.
This problem will give you a chance to get familiar with the MIPS instruction set, SPIM (a MIPS simulator) and the MIPS calling convention. You will learn SPIM's basic functionalities by simulating a MIPS assembly program at calculates the factorial of 5. You should read Chapter 2 and Appendix A (on the CD ROM) of P&H to prepare for this assignment. An on-line manual for SPIM can be found on the resources web-page.
Copy m:\lab1\fact.s to your home directory for this assignment. This program uses recursion to evaluate the factorial of 5 (f(N) = N * f (N - 1), f (0) = 1). Type spim (or m:\bin\spim) to start the windows version of the SPIM program. Load the assembly program fact.s by pressing the open button, typing the file name in the dialogue box, and clicking on 'open'. Observe that the instructions for your main program now appear in the Text Segments pane (Hint: you can go to the "Windows" drop down menu to select which pane you want to display). You are using the default mode of SPIM which supports the extended instruction set and has no delayed jumps or delayed loads.
1a) The program does not look exactly the same as in the fact.s file, because the some of the instructions are macros and SPIM translates them to bare machine instructions. However, the original codes are displayed as comments. What do the instructions "li" and "la" mean? How are they translated to bare machine instructions? Turn-in an annotated version of fact.s that shows how the "virtual machine" instructions are expanded or translated into native instructions.
1b) What is the starting address of the 'main' routine of 'fact'? Single-step the code from start until it reaches the first instruction of 'main'. Note that R31 has been modified. Which is the instruction that modified R31? What is the purpose of doing this?
1c) Set a breakpoint at the first instruction of the 'fact' routine. Continue tracing through the program execution by using single-stepping and breakpoints. What are the registers sp and fp used for? Draw the values on the stack when the first instruction of the fact procedure is about to be executed for the fourth time.
1d) Now it is time to switch from the virtual machine to the bare hardware. To run the bare machine, check the "bare machine" option in "Simulator->Settings". Then restart spim. This turns off the assembly language translations and imposes delayed jumps (and branches) as well as delayed loads.
Convert fact.s to use only the bare machine by translating the non-native instructions and by inserting NOPs after the jumps, branches, and loads. You will need to convert the call in main to fact back into a simple JAL. You might also need to take special actions to start executing the 'main' of 'fact'. Turn in this version along with verification that it works.
Turn off "bare machine" mode before starting Problem 2!
2a) Several assembly language instruction are expanded into a short sequence of machines instructions by the assembler. Show the expansions that would be used for the following instructions described in Appendix A: abs, mul, mulo, neg, rem, rol, li, sgt, bgeu, bgt, ulw.
2b) Write a procedure, itoa, in MIPS assembly language that will convert an integer argument into an ASCII decimal string. The procedure should take two arguments: The first argument is an integer in register $a0; the second argument is the address at which to write a result string in register $a1. The itoa procedure should convert its first argument to a null-terminated decimal ASCII string and store that string at the given result location. The return value from itoa, in register $v0, should be a count of the number of non-null characters stored at the destination.
Test itoa by running it on spim. Write a main() procedure that generates an ASCII string for each of the first 100 integers and prints them to the console using itoa(). Page A-43 (system-calls) from the book discusses how to print strings to the console. Turn in a transcript of the results.
Here is a list of things you should check for:
test case a
beq caseA_result, expected_Result, go_to_caseB
jump to failure A
test case b
addiu $t0, $0, 1
addiu $t0, $0, 2
Writing diagnostic programs can deepen your understanding of the instruction sets. The main purpose of this assignment, however, is not only to learn MIPS and understand the diagnostic process, but to teach you how to create programs that can be used to validate your design later in the semester. Since the final project only requires you to implement only a subset of the MIPS instruction set, the diagnostic programs in this assignment will only be useful later in the semester if they are written using this limited set of instructions. Hence, you must write the diagnostics using only the MIPS instructions below:
arithmetic: addu, subu, addiu
logical: and, or, xor, andi, ori, xori, lui
shift: sll, sra, srl
compare: slt, slti, sltu, sltiu
control: beq, bne, j, jr, jal
data transfer: lw, sw
Turn in a description of the specific errors that you found, the test code that excited the errors. Make sure to give a complete description of your testing strategy (methodology). We expect you to describe your testing methodology carefully and give us a notion of how systematic it was and why you were able to detect the bugs that you did. We are looking for an actual methodology here, including tests that didn't find bugs. Be systematic!