Homework Answers: Bitwise Operations and Shifting

 

  1. 1110 0101 1000
  2. 0010 1111 0101
  3. 0000 1110 0101
  4. 1111 0010 0101
  5. 1011 1110 0110
  6. 0001 1000 0100
  7. The bit pattern (in hex) is the immediate operand. To load this bit pattern it must be ORed with zero. Register $0 (also called $zero) always contains zero, so $0 will be the second operand. The first operand will be the register that will contain the bit string. For example, the following instruction loads the bit string 0011 1010 into $t1:
              ori     $t1, $0, 0x3a
    
  8. binary: 0000 0000 0000 0010 hex: 00 02
  9.           li      $t1, 0x02   #  or  ori     $t1, $0, 0x02
              or      $t2, $t2, $t1
    
  10. binary: 1111 1111 1111 1101 hex: FF FD
  11.           li      $t1, 0xFFFD   #  or  ori     $t1, $0, 0xFFFD
              and     $t2, $t2, $t1
    
  12. binary: 0000 0000 0100 1100 hex: 00 4C
  13.           li      $t1, 0004C   #  or  ori     $t1, $0, 0x004C
              or      $t2, $t2, $t1
    
  14. binary: 1111 1111 1011 0011 hex: FF B3
  15.           li      $t1, 0xFFB3   #  or  ori     $t1, $0, 0xFFB3
              and     $t2, $t2, $t1
    
  16.           ori     $t1,$0,0x02
              sll     $t2, $t1, 1
              sll     $t3, $t2, 1
              sll     $t4, $t3, 1
    
  17.           ori     $t1, $0, 0x01
              sll     $t2, $t1, 1
              or      $t1, $t1, $t2
              sll     $t2, $t1, 2
              or      $t1, $t1, $t2
              sll     $t2, $t1, 4
              or      $t1, $t1, $t2
              sll     $t2, $t1, 8
              or      $t1, $t1, $t2
              sll     $t2, $t1, 16
              or      $t1, $t1, $t2
    


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

© Copyright Emmi Schatz 2009