CSE 378 HomeWork 1

Winter 2004, Due: Wednesday 1/14/03

Purpose

The exercises here are intended to help you gain familiarity with the MIPS instruction set and instruction encoding. You'll do that by writing short sequences of MIPS instructions that achieve some desired effect.

You will turn-in programs written in machine code, represented as one or more 8-digit hexadecimal numbers (each of which is one MIPS R2000 instruction).

Before You Begin

Exercises

These exercises do not require any branches or immediate values
  1. Copy Register 8's (R8's) value into R9.

  2. R8 holds a 32-bit signed integer. R9 holds the value 0x00000001. Put the complement of R8 in R10. (E.g., 0x00000001 in R8 yields 0xFFFFFFFF in R10.)

  3. R8, which is of course 32-bits long, holds a bit string. R9 holds the value 0x00000001. Put in R10 the sum of bits 0 and bits 1 of R8. For instance, if R8 hold 0x1234567, R10 should end up with (decimal) value 2; if R8 holds 0x00000000, R10 should be set to 0; etc.

  4. R8 holds the main memory address of an array of bytes. R9 holds a (signed) integer index, which we'll call N. Set the Nth element in the array pointed at by R8 to 0x00. (Use 0-based array indexing - R8 points at the 0th element. Do not worry about "array bounds" issues.)

  5. R8 holds the main memory address of an array of 32-bit integers. R9 holds a (signed) integer index, which we'll call N. Set the Nth element of the array to 0. (Ditto...)

  6. R8 and R9 each contain signed integers. Form an 8-bit character by adding R8 and R9 and taking bits [3-10] from the result. Set R10 to the 32-bit integer value of that character.

  7. R8 contains a signed integer. Put R8+R8-R8 in R8. (This is a doubly trick question.)

Natural solutions to these exercises involve a single branch instruction (each), but no immediate values.

  1. R8 contains some bits. R9 contains 0x00000001. Put in R10 the number of bits of R8 that are 1. For example, if R8 is 0x30104800, R10 should end up with value 5.

  2. R8 and R9 contain signed integers. Put the larger of the two in R10.

  3. R8 points at an array of ASCII characters. Each character is in the range [a-z], or in the range [A-Z], or is a space. The array is terminated by a byte with value 0x00. R9 contains 0x00000020. Convert the string pointed at by R8 to upper case. (This can/should be done with a single branch instruction.)

These involve immediate values (but no branches).

  1. R8 holds the main memory address of an array of words. R9 holds a (signed) integer index, which we'll call N. Set the Nth word of the array to 0, using 1-based indexing (R8 points to the 1st element).

  2. Put 0x04000400 in R8.

  3. R8 points at an aray of integers. Put the address of the 13th element of that array in R9 (using 1-based addressing).

Turn-in

We'll use the turnin program. Details to be announced.