Practice ExamI-A Solution

# Practice ExamI-A Solution - ECE 2500 Practice Midterm...

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

ECE 2500 Practice Midterm Examination I-A Fall 2007 Name: __________________________________________ 1 20 2 20 3 10 4 7 5 6 6 10 7 8 8 10 9 6 10 3 Total 100 Instructions: This exam is closed book and notes. Calculators are not allowed. Do all of your work on the attached sheets and insert your answer in the space(s) provided. Remember, the more clear you show your work, the better chance you have for partial credit if your final answer is wrong. You have 75 minutes to complete the exam. The exam totals 100 points.

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

View Full Document
1. (20) Compile the following C++ function into MIPS assembly. You are not allowed to use pseudo-instructions with the exception of move instruction. Use the label degree2 to begin the procedure and mult to reference the called procedure (which, you don’t have to write). Be sure to comment your code! Save only what you have to on the stack. You have to use the below table as your guide for choosing the registers. int degree2(int a, int b, int x){ int x2, ax2, y; x2 = mult(x, x); ax2 = mult(a, x2); y = ax2 + b; return(y); } Possible solution: degree2: addi \$sp, \$sp, -12 # allocate 3 words sw \$ra, 8(\$sp) # save \$ra sw \$a0, 4(\$sp) # save \$a0 (a) sw \$a1, 0(\$sp) # save \$a1 (b) move \$a0, \$a2 # \$a0 = x move \$a1, \$a2 # \$a1 = x jal mult # x2 = mult(x,x) lw \$a0, 4(\$sp) # \$a0 = a move \$a1, \$v0 # \$a1 = x2 jal mult # ax2 = mult (a, x2) lw \$t0, 0(\$sp) # restore b add \$v0, \$v0, \$t0 # y = ax2 + b lw \$ra, 8(\$sp) # restore \$ra addi \$sp, \$sp, 12 # release 3 words jr \$ra # return Procedure Arguments Result mult \$a0, \$a1 \$v0 degree2 \$a0, \$a1, \$a2 \$v0
2. (20) Suppose that we have the following lines of C++ code. int i, x[10]; i = 0; while (i < 10) { x[i] += x[i+1]; i += 2; } Give MIPS assembly to implement this code. You have to use TAL instructions only. Use the below table as your guide for choosing registers. Again, comment your code.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/31/2008 for the course ECE 2500 taught by Professor Lnazhandali during the Spring '08 term at Virginia Tech.

### Page1 / 12

Practice ExamI-A Solution - ECE 2500 Practice Midterm...

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

View Full Document
Ask a homework question - tutors are online