CS447 Homework 3 - Due in Class - 2/14
  1. For each instruction in the code segment below, determine the instruction format, and the decimal and binary values of each instruction field.

  2.  
    and $s1, $zero, $zero # initialize $s1 to 0
    add $t0, $s0, $zero # set $t0 to the start address of some array
    loop: lw $t1, 0 ($t0) # copy a word from the array into $t1
    add $s1, $s1, $t1 # add the value of $t1 to the running total in $s1
    addi $t0, $t0, 4 # increment $t0
    bne $t1, $zero, loop # loop if word copied does not equal zero

  3. As discussed in your book on page 157, pseudoinstructions are not actually part of the MIPS instruction set but are often used in MIPS programs.  For each pseudoinstruction in the table below, produce the shortest possible sequence of actual MIPS instructions that accomplish the function described, using $at when necessary (the usage of the $at register is explained on page 147).  In the following pseudoinstructions, big represents a 32-bit number and small represents a 16-bit number.  Note: With the exception of bgt, these instructions have been created for the purposes of this homework only, and should not be used in actual MIPS programs.

  4.  
    Pseudoinstruction
    What it accomplishes
    dec $s0 $s0 = $s0 - 1
    quad $s0 $s0 = $s0 x 4
    swap $s0, $s1 $s0 = $s1 and $s1 = $s0
    swinc $s0, $t0 stores $s0 to address $t0 in memory
    and increments $t0 by 4
    subi $s0, $s1, big $s0 = $s1 - big
    bgt $s0, small, L if ($s0 > small) go to L

  5. Convert the following decimal numbers into 8-bit two's complement binary numbers:
    1. 123ten
    2. -96ten

  6. Convert the following decimal numbers into 16-bit two's complement binary numbers:
    1. 9023ten
    2. -746ten

  7. Convert the following 32-bit two's complement binary numbers into decimal numbers:
    1. 1111 1111 1111 1111 1111 1010 0010 1010two
    2. 0000 0000 0000 0000 0001 1100 1011 0001two

  8. Show the 8-bit two's complement representation of the decimal number 73, then show how to find the 16-bit two's complement representation of -73.

  9.  
  10. The andi and ori instructions are I-type instructions, and thus limit the masks to be 16 bits.
    1. Explain how these instructions affect the upper 16 bits of the result.
    2. How does this affect you as an assembly language programmer?  (i.e., under what circumstances is what MIPS does ok, and under what circumstances is it not ok?  When it is not ok, what do you have to do to overcome the problem?)

  11. You have been asked to implement a circuit for a graphics application.  This circuit consists of three inputs (Pixel1, Pixel2, and M) and one output (PixelOut).  When M equals 1, PixelOut should equal the disjunction (OR) of Pixel1 and Pixel2.  If M equals 0, PixelOut should equal the conjunction (AND) of Pixel1 and Pixel2.
    1. Construct a truth table to describe the behavior of the circuit.
    2. Write the logic function for PixelOut.
    3. Specify a PLA to implement this function.
    4. Show how to implement this function with AND and OR gates.