Computer Science 61CL - Spring 1998 - Clancy - Midterm 2

Computer Science 61CL - Spring 1998 - Clancy - Midterm 2 -...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
cs61c-exam2 CS 61C (Clancy) Exam 2 Problem 1 (4 points, 8 minutes) Given below is a MAL program segment that computes (x+1.0)^2 by adding x^2 to 2x, then adding 1 to that sum. .data x: .float answer: .float one: .float 1.0 .text _start: l.s $f4,x l.s. $f6, one mul.s $f8, $f4, $f4 # x^2 add.s $f8, $f8, $f4 # + 2*x add.s $f8, $f8, $f4 add.s $f8, $f8, $f6 # + 1.0 s.s $f8, answer Part a Consider the case where x is 2.0^12. What is the difference between the value stored in answer and the actual value of (2.0^12 +1.0)^2 ? (If the answer is the computed correctly, the difference will be 0.) Show your work. Part b Does the sequence in which the terms are added affect the correctness of the answer? Briefly explain. Problem 2 (6 points, 10 minutes) Translate the C/C++ function PrintDownUp to MAL, retaining its recursive structure, passing its argument in the appropriate register, and following the usual register conventions. Translate putchar into a putc pseudoinstruction whose register argument contains the character to print. void PrintDownUp (char c) { if (c=='a') { putcher (c); file:///C|/Documents%20and%20Settings/Jason%20Raft. ..20Spring%201998%20-%20Clancy%20-%20Midterm%202.htm (1 of 4)1/27/2007 6:35:27 PM
Background image of page 1

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

View Full DocumentRight Arrow Icon
cs61c-exam2 } else { putchar (c); PrintDownUp (c-1); putchar (c); } } Problem 3 (8 points, 15 minutes)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/26/2009 for the course CS 61CL taught by Professor Clancy during the Fall '08 term at University of California, Berkeley.

Page1 / 4

Computer Science 61CL - Spring 1998 - Clancy - Midterm 2 -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online