CS61C Fall 2016 Lab 4 - Function Calls and Pointers in MIPS

Goals

These exercises are intended to give you more practice with function calls and manipulating pointers in MIPS.

Setup

Copy the lab files with

$ cp -r ~cs61c/labs/04/ ~/labs/04 

Exercises

Exercise 1

Write two versions of a function named first1pos (starting from first1pos.s) that, given a value in $a0, returns in $v0 the position of the leftmost bit in the word in $a0. If $a0 contains 0, store -1 in $v0. You are allowed to modify $a0 in the process of finding this position. Positions range from 0 (the rightmost bit) to 31 (the sign bit).

One of your solutions should repeatedly shift $a0, checking the sign bit at each shift. The other should start a mask at 0x80000000 and repeatedly shift it right to check each bit in $a0.

Checkoff