CS232 Fall 09 Solutions

# CS232 Fall 09 Solutions - CS 232 Exam 1: Solutions Fall...

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

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.

Unformatted text preview: CS 232 Exam 1: Solutions Fall 2009 1. Bitwise operations (20 points) : Registers a0 , a1 and a2 are 32-bit signed integers in two’s complement representation. Write a MIPS function without using branches that returns a non-zero value if the majority sign is negative, and returns a zero value if the majority sign is positive. majority: # data in \$a0, \$a1, \$a2 srl \$a0, \$a0, 31 # keep just the sign bit srl \$a1, \$a1, 31 # keep just the sign bit srl \$a2, \$a2, 31 # keep just the sign bit add \$v0, \$a0, \$a1 add \$v0, \$v0, \$a2 # add all the sign bits srl \$v0, \$v0, 1 # integer divide by 2 (could also do sra here) jr \$ra 2. C++ to MIPS (25 points) : Translate the following C++ function into MIPS. Assume that the function hash (which returns an int ) has already been translated for you. Be sure to follow all calling conventions! int func(int n, int m) func: # a0 = n, a1 = m { addi \$sp, \$sp, -12 if(hash(n) < hash(m)) sw \$a1, 0(\$sp) # save m return hash(n); sw \$ra, 4(\$sp) return hash(m); jal hash }...
View Full Document

## This note was uploaded on 04/24/2010 for the course CS 232 taught by Professor Garzaran during the Fall '08 term at University of Illinois at Urbana–Champaign.

### Page1 / 2

CS232 Fall 09 Solutions - CS 232 Exam 1: Solutions Fall...

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

View Full Document
Ask a homework question - tutors are online