# Quiz3 - int foo(int x) { if (x <= 0) return 1; else...

This preview shows page 1. Sign up to view the full content.

CDA3101 Quiz 3 Last Name ____________________ Fall 2010 First Name ____________________ 1. In a CDA3101 assignment, students were asked to translate the recursive C function foo() shown below into MIPS assembly code. The MIPS code shown below is a solution provided by a student. You have to play the role of the TA and find and correct all the errors (logical or otherwise) as well as situations where procedure call conventions are not followed in this MIPS code.
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int foo(int x) { if (x <= 0) return 1; else return (x * foo(x-2)); } Strike each instruction you think is wrong and write the correct instruction next to it. If you need to add an instruction, write that instruction and draw an arrow to show where that instruction will go. Make only necessary changes foo: blez \$a0, base addi \$sp,\$sp, -4 sw \$ra, 0(\$sp) addi \$a0,\$a0,-2 j foo lw \$ra,0(\$sp) mul \$v1,\$v1,\$a0 base: jr \$ra...
View Full Document

## This note was uploaded on 01/15/2012 for the course CDA 3101 taught by Professor Small during the Summer '08 term at University of Florida.

Ask a homework question - tutors are online