title: Determining sign of a number
body: <p>I'm just trying to branch to a different segment of code given a number is positive or negative, using MIPS assembly, this is the short segment which is supposed to do just that:</p>
  
  <pre><code>lbu $4, digit
  and $5, $4, 0x80
  srl $5, $5, 31
  bgt $5, 0, positive
  b negative
  </code></pre>
  
  <p>The digit is successfully in $4, I bitwise AND it against a 1 with all following zeros in order to get whether the first bit is 1 or 0, then I shift right 31 bits so it's in the last position, and then I check if its greater than 0, and if so, branch positive, else, branch negative.</p>
  
  <p>I'm sure I'm messing up the logic somewhere, and I'm also unsure if I can use 0 like that (in bgt), or if I should be using $0</p>
  
  <p>Any ideas? Thanks!</p>