CSE 30 -- Lecture 4 -- Oct 9


Assignment: Read the file that you ran with xspim (../public/assn1.asm) and add English comments to it explaining what its doing. Do not simply have comments of the form ``set register $v0 to the constant value 8'' -- that just repeats what the opcode says and does not provide any new information to the reader; instead, you should explain what is going on, e.g., ``prepare to make syscall number 8, read_string''. Also, you must fix the bug that causes it to print colons, semicolons etc -- it should be printing a string of hexidecimal digits (0, 1, ... , 8, 9, A, B, C, D, E, F).

The assignment is due before class next Wednesday (Oct 16). Again, use the turnin program to turn in your assembly file. The comments that you add should be part of the assembly source file. You should test it to be sure that it works for all inputs (e.g., input cs30fzz should not contain a colon character in the output).

When you comment your code, make sure that the comment is not just true for the first time through loops.

I went over in class the MIPS registers and their usage convention, and how function calls are done using the normal function call convention (see the Larus handout. As an example, I went over the fib function to calculate the fibonacci function. In C, it is:

/* assume n >= 0 */
int	fib(int	n)
{
	if (n <= 1) {
		return 1;
	} else {
		return fib(n-1) + fib(n-2);
	}
}
The fibonacci sequence is defined by fib(0) = fib(1) = 1, and fib(n) = fib(n-1) + fib(n-2) for all n greater than 1.

The MIPS assembly language implementation of this is available in the public directory (fib.asm). You should refer to the text (chapter 3), or to the Larus handout to figure out what each of the instructions do. You are encouraged to grab this file and run it under xspim. You probably don't want to evaluate fib for n larger than 23 or so, since this is the slow, recursive algorithm. Play with in. If you're motivated, try changing this to implement some other function, e.g., exponentiation by repeated squaring.


[ CSE 80 | ACS home | CSE home | CSE calendar | bsy's home page ]
picture of bsy

bsy@cse.ucsd.edu, last updated Wed Oct 23 14:22:14 PDT 1996.

email bsy