CSE 230 Spring 2011 (Section 1 and 2)
Quiz1: Feb 1st, on class.  30 Mins.

((Books, notes, computer allowed)

1.    Write the MIPS instructions for each of the following. Do not write an entire program, just the instructions needed. Use $s0 for a, $s1 for b and $s2 for c. Use other registers as needed.

b = c + b – a

add $s1,$s2,$s1

sub $s1,$s1,$s0

 

          b = a – 7 + c

addi $s0,$s0,-7

add $s1,$s0,$s2

 

 

          c = a * 2 + ( b – 1 )

add $s2,$s0,$s0

addi $s1,$s1,-1

add $s2,$s2,$s1


 

2.       Give the contents of the registers after the code segment is executed. Assume initial values are 0.
Give all answers as 8 hexadecimal digits. (Each segment [a, b, etc] is independent.)

 

a.         addi     $s0, $0, 4

   sll         $s0, $s0, 5  # SLL -> Shift Left Logical, by number

                                                # of iots in instruction, zeroes are shifted in

   srl         $s1, $s0, 2 # SLL -> Shift Right Logical, by ..ditto

 

 

$s0         0x0000 0080                                  $s1            0x0000 0020

           

b.         lui         $s0, 0x1001

   ori         $s0, $s0, 0x1001

   sll          $s0,  $s0, 1

   slr          $s1, $s0, 2

 

 

$s0          0x2002 2002                                 $s1             0x0800 8800

           

c.        addi     $s0, $0, 15    # Bitwise AND

addi      $s1, $0, -1

and       $s0, $s0, $s1

andi      $s1, $s1, 0x0040

 

 

$s0           0x0000 000F                                $s1          0x0000 0040

 

d.        ori       $s0, $s0, 0x1234

nor        $s0, $s0, $0   # Bitwise NOR. NOR = NOT OR

addi       $s1, $s1, 1

nor         $s1, $s1, $0

 

 

$s0         0xFFFF EDCB                                  $s1         0xFFFF FFFE