title: Get value of a compare instruction
body: <p>As I understand it, a cmp instruction will set some of the bits in your flags register. You can then use instructions like jle, jnp, etc. to branch based on those.</p>
  
  <p>What I am wondering is how you can recover an integral value from a comparison.</p>
  
  <p>Example: The following is valid c syntax</p>
  
  <pre><code>y = x[a &gt;= 13];
  </code></pre>
  
  <p>So a is compared with 13 to get a true or false which is interpreted as 1 or 0 respectively. However, that 1 or 0 must be fed into the array access as an integer. What will the compiler do?</p>
  
  <p>Some things that I can think of are:</p>
  
  <p>Do the comparison and then branch to either x[0] or x[1]</p>
  
  <p>Do the comparison and then branch to do either tmp = 0 or tmp = 1 then do x[tmp]</p>
  
  <p>Maybe do some fancy logic on the flags (not sure if there are instructions to access the flags directly)</p>
  
  <p>I've tried to look at what gcc spits out for this code example but it's impossible to pick out the logic from within all of the extra junk it throws in.</p>
  
  <p>I am working on a compiler so any suggestions would be appreciated.</p>