CSE 378 HomeWork 1

Winter 2006
Due: Friday 1/13/06

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.

Note that we don't intend you to run your programs, except by hand simulation.

Before You Begin

  • Reference Information The most relevant parts of the R2000 instruction set are listed in Appendix A.10 of the text. Their operation is described in Chapter 2 (or can be devined from what is in Chapter 2.) The full instruction set is described in MIPS32 Architecture for Programmers, Volume II, a copy of which is reference linked from the miscellaneous documentation page for this course.

  • Documentation Gotcha "Instructions" that are tagged with pseudoinstruction in A.10 are NOT instructions, and should not be used.

  • Registers You can use any registers you want, EXCEPT DO NOT USE register $31. Also, remember that $0 is 0, no matter what you try to do to it.

  • Do No Harm You should not change the values of any operands in any exercise, unless explicitly asked to do so as part of the function desired. For instance, if the exercise is to put the larger of registers 1 and 2 into register 3, registers 1 and 2 should have their original values when your code completes (while register 3 obviously is overwritten).
  • Assembler Exercises

    Hand in short bits of assembler code for these exercises.

    1. Copy $8's value into $9.

    2. Put 0x12348ABC in $9. (Be careful.)

    3. $8 holds a 32-bit signed integer. Put the two's-complement of $8 in $9 (assuming that is possible). (E.g., 0x00000001 in $8 yields 0xFFFFFFFF in $9.) Do not generate overflow, no matter what.

    4. $8 holds the main memory address of the 0th byte of an array of bytes. $9 holds an integer index, which we'll call N. Set the Nth element in the array pointed at by $8 to 0x00. You can use $10 as a temporary (i.e., you can destroy whatever value it has when your code starts). (Do not worry about "array bounds" issues.)

    5. $8 holds the address of the 0th byte of an array of 32-bit integers. Set the 4th element of the array (the one with index 3) to 0.

    6. $8 holds the address of the 0th byte of an array of 32-bit integers. $9 holds a (signed) integer index, which we'll call N. Set the Nth element in the array pointed at by $8 to 0x00000001. Use as few additional registers as temporaries as you can.

    7. Swap the contents of $8 and $9. Do not modify any other registers.

    8. $8 contains a signed integer. Put $8+$8-$8 in $8. You can use $9 as a temporary. (This is a doubly trick question.)

    9. $8 and $9 contain signed integers. Put the larger of the two in $10.

    10. $8 contains some bits. Put in $9 the number of bits of $8 that are 1. For example, if $8 is 0x30104800, $9 should end up with value 0x00000005. You can use $10 and $11 as temporaries.

    Machine Language

    Give the machine code, in hex, for the following bit of assembler. Assume the first instruction is loaded in memory at address 0x00001000.
                 add  $8, $8, $12
    loop:        addi $8, $8, 12
                 lw   $9, -4($8)
                 bne  $9, $0, skip
    	     sub  $8, $8, $9
    skip:        j    loop
    

    Turn-in

    To be determeind.