sp99 prerequisite quiz solution

# Computer Organization and Design: The Hardware/Software Interface

• Homework Help
• davidvictor
• 9

This preview shows pages 1–5. Sign up to view the full content.

1 University of California, Berkeley College of Engineering Computer Science Division EECS Spring 1999 John Kubiatowicz Prerequisite Quiz February 1, 1999 CS152 Computer Architecture and Engineering This prerequisite quiz will be used in determining class admissions. The use of calculators or notes is not allowed during this quiz. Good Luck! Your Name: SID Number: Discussion Section: 1 2 3 4 Total

This preview has intentionally blurred sections. Sign up to view the full version.

3 1) Assume that we have a 16 bit system that uses signed, two’s-complement integers. Perform the following conversions: -8 10 to base 2: 1111 1111 1111 1000 2 D458 16 to base 2: 1101 0100 0101 1000 2 24 10 to base 16: 0018 16 (1111110110101100) 2 to base 16: FDAC 16 FC34 16 to base 10: 1111 1100 0011 0100 2 = -(0000 0011 1100 1011 2 + 1) = -(0000 0011 1100 1100 2 ) = -(512+256+128+64+8+4)= -972 10

This preview has intentionally blurred sections. Sign up to view the full version.

4 2) Suppose that we start with the following C program for factorial: int fact (int n) { if ( n < 1 ) { return 1; } else { return n fact (n-1); } } Here is a translation of the program above into MIPS assembly language. fact: slti \$s0 ,\$a0,1 Callie saves reg! (Use \$t0, not \$s0) bne \$s0 ,\$zero,L1 Must be “ beq”. ( Also use \$t0): beq \$t0, \$zero, L1 addi \$v0,\$zero,1 jr \$ra L1:subi \$sp,\$sp,2 Need to adjust by 8 (2 words) sw \$a0,0(\$sp) Must also save \$ra: Insert instruction sw \$ra,4(\$sp) subi \$a0,\$a0,1 jal fact Must restore argument. Insert: lw \$ra,0(\$sp) lw \$ra,4(\$sp) addi \$sp,\$sp,2 Need to adjust by 8 (2 words) mult \$v0,\$a0,\$v0 Pseudo-op should be called “ mul ” or,
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern