Midterm 1 CS61C Summer 2001 - University of California, Berkeley, Exams of Computer Science

The material for midterm 1 of the cs61c summer 2001 course at the university of california, berkeley. It includes various programming problems that students are expected to solve using c source code, mips assembly instructions, and mal (mips assembly language) instructions. The document also includes short answer questions related to mips architecture and c programming.

Typology: Exams

Pre 2010

Uploaded on 11/07/2010

koofers-user-468
koofers-user-468 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
file:///C|/Documents%20and%20Settings/Jason%20Raftery/My%20D...nce%2061C%20-%20Summer%202001%20-%20Yu%20-%20Midterm%201.htm
CS61C Summer 2001
Midterm #1
Professor Woojin Yu
Problem #1
Rewrite the following C source code using only the MIPS Assembly instructions. Please follow register conventions
mentioned in class.
int func1(int *a)
{
int *temp;
if (*a)
{
temp = a;
a++;
return(*temp+func1(a));
}
else
return 0;
}
Problem #2
In the following, some of the statements are incorrect or illegal; cross out any such bad statements. Show in the spaces
provided what the remaining print statements will print when the program is executed. Briefly state why the illegal statements
are wrong.
int main()
{
char a = 'A', ur[] = "ORDINALS", b = 'C';
char *alpha = &a, *beta = alpha, *gamma = ur;
char **aleph = &alpha, **beth = β
printf("%c\n", *gamma);
printf("%s\n", b);
printf("%c\n", *beta);
printf("%c\n", alpha);
file:///C|/Documents%20and%20Settings/Jason%20Raf...0-%20Summer%202001%20-%20Yu%20-%20Midterm%201.htm (1 of 4)1/27/2007 6:35:28 PM
pf3
pf4

Partial preview of the text

Download Midterm 1 CS61C Summer 2001 - University of California, Berkeley and more Exams Computer Science in PDF only on Docsity!

CS61C Summer 2001

Midterm

Professor Woojin Yu

Problem #

Rewrite the following C source code using only the MIPS Assembly instructions. Please follow register conventions mentioned in class.

int func1(int a) { int temp; if (a) { temp = a; a++; return(temp+func1(a)); } else return 0; }

Problem #

In the following, some of the statements are incorrect or illegal; cross out any such bad statements. Show in the spaces provided what the remaining print statements will print when the program is executed. Briefly state why the illegal statements are wrong.

int main() { char a = 'A', ur[] = "ORDINALS", b = 'C'; char *alpha = &a, *beta = alpha, *gamma = ur; char **aleph = &alpha, **beth = β

printf("%c\n", *gamma);

printf("%s\n", b);

printf("%c\n", *beta);

printf("%c\n", alpha);

alpha = ur + 1;

printf("%c\n", *(ur + 3));

printf("%s\n", &ur[1]);

ur = alpha;

printf("%c\n", *beta);

beth = &(alpha);

if ( (aleph)[1] == (beth)[1] ) printf("CH is true.\n");

Else printf("CH is false.\n");

return0; }

Problem #

Convert this MIPS machine code into MAL (MIPS Assembly Language) instructions. Your final answers should use the register names, not the numbers(i.e. $t0, not $8) Also, values which represent addresses (if any) should be converted into the full 32 bit address.

ADDRESS: Instructions: 0x10001A00 001000 11101 11101 11111 11111 111100 0x10001A04 101011 11101 11111 00000 00000 000000 0x10001A08 000011 00000 10000 01000 00000 000111 0x10001A0C 000000 00010 00010 00010 00000 100000 0x10001A10 100011 11101 11111 00000 00000 000000 0x10001A14 001000 11101 11101 00000 00000 000100 0x10001A18 000000 11111 00000 00000 00000 001000

Posted by HKN (Electrical Engineering and Computer Science Honor Society) University of California at Berkeley If you have any questions about these online exams please contact mailto:[email protected]