title: How to calculate the Auxiliary Flag status in x86 Assembly
body: <p>How is the Auxiliary Flag calculated in x86 Assembly?</p>
  
  <p>The majority of the <a href="https://stackoverflow.com/questions/36492553/how-to-set-auxiliary-flag-for-16bits-binary-addition?rq=1"> resources</a> I can find explain that, the Auxiliary Flag is set to '1' if there is a carry from bit 3 to bit 4. </p>
  
  <p><a href="https://en.wikipedia.org/wiki/Half-carry_flag" rel="nofollow noreferrer">Wiki :</a></p>
  
  <blockquote>
    <p>It indicates when a carry or borrow has been generated out of the least significant four bits of the accumulator register following the execution of an arithmetic instruction.</p>
  </blockquote>
  
  <p>Example:</p>
  
  <pre><code>mov al,-14 *(1111 0010)
  mov bl,-130 (0111 1110)
  sub al,bl (1111 0010 – 0111 1110)
  </code></pre>
  
  <p>*<sub> the brackets show the stored binary patterns. </sub></p>
  
  <p>Result: <code>1111 0010 – 0111 1110</code> will be calculated as <code>1111 0010 + 1000 0010</code> using two's complement, giving the result <code>0111 0100 + OF</code>.</p>
  
  <p>In the example given the AF is set (=1). I do not understand why this is, as I cannot see that there has been a carry from bit 3 to bit 4. The addition of <code>0010</code> + <code>0010</code>, the least significant nibble, equals <code>0100</code>, no carry. The least significant four bits of the accumulator register, have changed from <code>0010</code> to <code>0100</code> ('2' to '4'), there has been no carry from the lower nibble to the higher nibble?</p>
  
  <p>Please could someone kindly explain where my thinking has gone awry?</p>
  
  <p>I have a suspicion that the abundance of 'negatives' is throwing me off at some point, as I have tried several different examples in the debugger and they all act in accordance with my expectations, bar this one example. </p>