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
Unformatted text preview: CS 232 Exam 1: Solutions Fall 2009 1. Bitwise operations (20 points) : Registers a0 , a1 and a2 are 32bit signed integers in two’s complement representation. Write a MIPS function without using branches that returns a nonzero 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.
 Fall '08
 Garzaran

Click to edit the document details