title: How to get BSR instruction to work on 64 bits?
body: <p>I am trying to find the leading bit of a unsigned 64bit int. I am using BSR as my processor doesn't have the LZCNT instruction. My problem is that once the input is exactly  2^32, it returns 2^64 as the leading bit value, then cycles back through outputs up until 2^64.</p>
  
  <p>This is my code:</p>
  
  <pre class="lang-c prettyprint-override"><code>unsigned long int LeadingBit(unsigned long int a) {
    if(a==0)
      return 0;
    unsigned long int nlb;
    asm (
         "BSR %1, %0   \n"
         : "=r" (nlb)
         : "mr" (a)
         : "cc"
         );
    return 1&lt;&lt;nlb;
  
  }
  </code></pre>
  
  <p>The intention of this code is to be able to input a 64-bit integer, and have it return the value of the position of the leading 1. e.g:
  a = 65 (1000001)
  returns 1000000.</p>