title: Sub instruction in assembly and the effect on CF and AF
body: <p>It seems that <strong>CF</strong> (carry flag) and <strong>AF</strong> (auxiliary flag) are tricky when using <code>sub</code> command. For example (first case is correct and easy to understand):</p>
  
  <pre><code> AL=4CH, BL=29H          (C&gt;9 , 4&gt;2)
   SUB AL,BL     ; AL=23H       CF=0   AF=0
  
   AL=44H, BL=29H          (4&lt;9 , 4&gt;2)
   SUB AL,BL     ; AL=1BH       CF=0   AF=1
  
   AL=1CH, BL=29H          (c&gt;9 , 1&lt;2)
   SUB AL,BL     ; AL=F3H       CF=1   AF=0   ALSO SF=1
  
   AL=13H, BL=29H          (3&lt;9 , 1&lt;2)
   SUB AL,BL     ; AL=F3H       CF=1   AF=1   ALSO SF=1
  </code></pre>
  
  <p>Now take the second case for more details</p>
  
  <pre><code> 0100 0100
   0010 1001 -
  ------------
   0001 1011
  </code></pre>
  
  <p>There is no borrowing from AH to AL. So why the second case results in AF=1?</p>
  
  <p>Regarding the third case, we borrow from AH. So in my opinion, CF=0 and AF=1. But the result is different from what I understand. Why?</p>