University of California, San Diego
Dept. of Computer Science and Engineering
CSE 30 โ Computer Organization and Systems Programming
Problem Set #4 โ Due 2pm Thursday November 12, 2009
1. Convert the following C function to MIPS assembly code. Use only real MIPS instructions and
follow all MIPS function calling conventions.
void swap(int *px, int *py){
int temp;
temp = *px;
*px = *py;
*py = temp;
}
2. Convert the following C function to MIPS assembly code. Use only real MIPS instructions and
follow all MIPS function calling conventions.
int strlen(char *s)
{
char *p = s;
while(*p != 0)
p++;
return p-s;
}
3. The McCarthy 91 function is a recursive function which returns 91 for all integer arguments n โค
100 and returns n โ 10 for n > 100. It was conceived by computer scientist John McCarthy.
a. Write MIPS assembly code for the following C/Java program fragment, which computes
the McCarthy 91 function. You must follow all MIPS function call standards, and must
only use real MIPS instructions (no pseudoinstructions)
int McCarthy91(int n)
{
int result;
if(n > 100)
result = n โ 10;
if(n <= 100)
result = McCarthy91(McCarthy91(n+11));
return result;
}
b. Assume that every instruction takes one cycle. How many cycles does your code require
when you call McCarthy(99)? Extra credit given for the code that requires the least
amount of cycles.
4. Convert the following hexadecimal numbers to their MIPS instruction:
a. 0x3C019000
b. 0x10040004
c. 0x8c240180
d. 0x0C000000