CMPS-2240 Homework #5: Bitwise Logic

This homework covers MIPS bit manipulation facilities in depth.
All answers are in the MIPS Tutorial 11 - 12.
Answer the questions as you work through the tutorial.
Read completely:
Use as needed:

1. Where is the operand 0x2 placed in the binary encoding of this instruction?

        ori $8, $0, 0x2

2. All MIPS registers are 32-bits. That means that $0 is a bit string of 32 zeros. The operand in this bitwise immediate OR is only 16 bits. How does MIPS handle this?
           ori $8, $0, 0x2

3. Explain this MIPS instruction and give the result.
           ori $8, $0, 0x2 

4. Can you use ori to load a register with a signed integer?

5. What is wrong with the following instruction?
        ori  $0, $9, 0x32

6. What is loaded into $10 when you execute this code?
    ## Program to bitwise OR two patterns 
   .text
   .globl  main
main:
    ori   $8,$0,0x0DA5    # put first pattern into register $8
    ori   $10,$8,0x368F   # or ($8) with second pattern.  Result to $10.
## End of file

7. Explain in detail what this instruction does and give the result.
         andi $8, $0, 0xFFFF

8. What is in $8, $9, and $10 after this program executes? Test in spim:
 spim> re "q8.s" 
 spim> breakp main
 spim> run
 spim> s 
 spim> p $8  
 spim> s 
 spim> p $9
 spim> s 
 spim> p $10 

# file: q8.s
        .text
        .globl  main
main:
        ori     $15, $0,0x0DA5       # load bit pattern register into $15
        ori      $8,$15,0x368F       # OR with second pattern
        andi     $9,$15,0x368F       # AND with second pattern
        xori    $10,$15,0x368F       # XOR with second pattern
## End of file

9. Let b1 and b2 be loaded as shown below. What is in b1 after these C xor operations? Is there a generalization you can make for any arbitrary bit string?
    // load b1 with 1011
    a) b1 = b1 ^ b1;  // caret in C is bitwise exclusive or

    // load b1 with 1010 and b2 with 1001
    b) b1 = b1 ^ b2;  
       b2 = b2 ^ b1; 
       b1 = b1 ^ b2;


Starting Tutorial 12

10. What is the outcome of these MIPS instructions?
      ori  $9,  $0, 0x5 
      sll  $10, $9, 3