title: Bits Manipulation MiPS Assembly
body: <p>The program takes a user input key, extracts the rightmost 5 bits from that key, then replaces those bits in between bits 2 to 6. </p>
  
  <p>This is what I've tried. </p>
  
  <pre><code>lw $s1, 0($s0)               # extracts the first word in the array
  beq $s1, $zero, done         # at the end of the array is a zero =&gt; 0
  
  
  move $t1, $s2                 #s2 has the input key
  move $t0, $s1                 # put the word in a temporary register
  andi $t2, $t1, 0x0000001f     # use the input mask to return the rightmost 5 bits
  
  sll $t3, $t2, 2               # move the bits over to align with bits 2-6
  
  andi $t0, $t3, 0xffffff83
  </code></pre>
  
  <p>So my thinking is to take the input key, extract the 5 bits with andi $t2, $t1,0x0000001f, then shift left logical two bits to align the extracted 5 bits with bits 2 to 6.</p>
  
  <p>This is where I'm stuck. How do I replace the bits that I took from the user input key and put them in the bit locations 2 through 6? The input mask for the second andi I believe is correct but I don't think I'm using the proper registers.  </p>
  
  <p>EDIT: Thank you for the replies. I figured out the solution with the provided suggestions. For anyone having a similar problem:</p>
  
  <p>I removed the andi at the bottom. And to avoid providing the full answer, the bits that need to be replaced in the data word will have to be modified with an input mask. This can be done with a different andi instruction. There are a couple more steps but this should at least point anyone in the right direction for the future. </p>