Snyder 7 April 2000

Programming Assignment #1

The goal of this assignment is to give you experience with writing assembly language code for the MIPS ISA. The actual computation is simply an exercise to provide opportunities to write simple procedures using the basic R-type and branching instructions. The problem is to write a generalized shifter, capable of shifting not just a single word, but a vector of words. The inputs to your program are as follows:

$a0 contains the base address of a vector of words

$a1 contains the number of words in the vector

$a2 contains the number of bits to shift the vector 0 <= $a2 <= 32

The program is to shift the vector $a2 bits to the right. The output of the program is the first two words of the array in registers $v0 and $v1.

To solve the problem write a procedure that shifts a single word right or left by a given amount. Call the procedure "scooch". The procedure has the following inputs

$a0 contains a word that is to be shifted

$a1 contains a 0 or 1 indicating whether the shift is right (0) or left (1)

$a2 contains the amount to be shifted

The scooch procedure shifts the word in $a0 right or left (as given by $a1) by the amount specified in $a2. Zeros are to be used as fill. The procedure should use a loop, shifting the word by one on each iteration. The result of the procedure should be returned in $v0.

The overall programming assignment uses an algorithm in which a word is shifted right by $a2 and shifted left by 32-$a2. The first word is replaced by its right shifted form, subsequent words are replaced by their right shifted form combined with the left shifted form of the previous word. Although the first word can be set up specifically, all of the subsequent words should be constructed in a loop.