w05-final-solution

# w05-final-solution - ECE 30 Introduction to Computer...

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

ECE 30 Introduction to Computer Engineering Final Exam March 18, 2005 Name Solution Student ID Signature Topic Your score out of 1 Assembly language 10 2 Computer arithmetic 10 3 CPU design 10 4 Cache organization 10 5 Virtual memory 10 Total 50 You may only use the MIPS assembly instructions listed in table 1 on the last page. Do not use pseudo-instructions or invent new instructions.

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

View Full Document
1. Assembly Language Programming (10 points) Write a recursive procedure ‘ fibonacci ’ in MIPS R2000 assembly language that com- putes the n th Fibonacci number deﬁned recursively as f ( n ) = f ( n - 1)+ f ( n - 2) for n > 2 and f (1) = f (2) = 1 . Assume that the argument n is a positive integer. The following is a C version of the routine: int fibonacci (int n) { if (n > 2) return fibonacci(n-1) + fibonacci(n-2); else return 1; } Assume that n is passed to ‘ fibonacci ’ in \$4 and ‘ fibonacci ’ returns the result in \$2. Note that the stack grows downward in R2000. As in the hanoi project, you must store all local variables in the stack frame. Note that the stack pointer and the frame pointer are stored in \$29 and \$30 respectively. 2
(continued) fibonacci: # first test for n = 1 or 2 addi \$2, \$0, 1 # f(0) = f(1) = 1 addi \$8, \$0, 3 # \$8 = 3 slt \$1, \$4, \$8 # if n < 3, done bne \$1, \$0, fdone # allocate stack frame sw \$4, 0(\$29) # store n in stack frame # leave one space open for f(n-1) sw \$30, -8(\$29) # old frame pointer sw \$31, -12(\$29) # return address addi \$30, \$29, 0 # new frame pointer addi \$29, \$29, -16 # compute f(n-1) addi \$4, \$4, -1 jal fibonacci sw \$2, -4(\$30) # store f(n-1) in stack frame # compute f(n-2) lw \$4, 0(\$30) # first retrieve n addi \$4, \$4, -2 # n - 2 jal fibonacci lw \$9, -4(\$30) # retrieve f(n-1) add \$2, \$2, \$9 # f(n) = f(n-1) + f(n-2) # deallocate stack frame addi \$29, \$29, 16 # pop stack frame lw \$30, -8(\$29) # restore old frame pointer lw \$31, -12(\$29) # return address fdone: jr \$31 3

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

View Full Document
2. Computer Arithmetic (10 points) The goal of this problem is to design and analyze an adder that adds three 8-bit unsigned numbers and generates a 10-bit sum using a fast addition scheme called the carry save method. (a) (1 point) Design a 1-bit CSA, which takes three 1-bit numbers and outputs a two- bit number, using the full adder shown below. Note that the weight of the carry-out bit ( c out ) is twice that of the sum bit ( s ). Therefore, if a = b = c in = 1 (so that s = c out = 1 ), we can view the output as a two-bit number 11 with c out as the MSB and s as the LSB. The inputs for the 1-bit CSA must be labeled a , b , and c and the outputs s 1 and s 0 . FA a b s c in c out a b c s 1 s 0 (b) (1 point) Design an 8-bit CSA using the 1-bit CSA shown below as building blocks. The outputs of the 8-bit CSA must be in the
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 06/09/2008 for the course ECE 30 taught by Professor Gert during the Spring '08 term at UCSD.

### Page1 / 14

w05-final-solution - ECE 30 Introduction to Computer...

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

View Full Document
Ask a homework question - tutors are online