Homework: Bitwise Operations and Shifting

 

Recall that we number the bits starting from 0 at the low order (rightmost) bit and go up to bit 31 at the high order (leftmost) bit.

  1. Shift left logical the following bit pattern by 2 positions: 0011 1001 0110
  2. Shift right logical the following bit pattern by 2 positions: 1011 1101 0110
  3. Shift right arithmetic the following bit pattern by 2 positions: 0011 1001 0110
  4. Shift right arithmetic the following bit pattern by 2 positions: 1100 1001 0110
  5. What is the bitwise OR of the following bit strings?
              1011 1100 0100
              0001 1010 0110
    
  6. What is the bitwise AND of the following bit strings?
              1011 1100 0100
              0001 1010 0110
    
  7. How can you use the ori instruction to load a bit pattern into a register? What value will you OR with your bit pattern? What register always contains this value?
  8. What mask will you use to set bit 1? Give the mask in binary and in hex.
  9. Write the MIPS instructions to load this mask into $t1 and set bit 1 of $t2.
  10. What mask will you use to reset bit 1? Give the mask in binary and in hex.
  11. Write the MIPS instructions to load this mask into $t1 and reset bit 1 of $t2.
  12. What mask will you use to set bits 2, 3, and 6? Give the mask in binary and in hex.
  13. Write the MIPS instructions to load this mask into $t1 and set bits 2, 3, and 6 of $t2.
  14. What mask will you use to reset bits 2, 3, and 6? Give the mask in binary and in hex.
  15. Write the MIPS instructions to load this mask into $t1 and reset bits 2, 3, and 6 of $t2.
  16. Write the instructions which will do the following: in each register $t1 through $t4 set the corresponding bit. That is, in register $t1 set bit 1 (and clear the rest to zero), in $t2 set bit 2 (and clear the rest to zero), and so on. Use only one ori instruction in your program, to set the bit in register $t1.
              ori   $t1,$0,0x02
    
    Don't use any ori instructions other than that one. Note: bit 1 of a register is the second from the right, the one that (in unsigned binary) corresponds to the first power of two.
  17. Start out a program with the instruction that puts a single one-bit into register $t1:
              ori   $t1,$0,0x01
    
    Now, by using only shift instructions and register to register logic instructions, put the pattern 0xFFFFFFFF into register $t1. Don't use another ori after the first. You will need to use more registers than $t1.


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2009