Search code examples
assemblyemu8086eflags

How to jump if the AF flag is 1?


I want to check if auxiliary carry flag is 1 then do something. I can't find any reference regarding only auxiliary carry flag.

mov al,00011010b
mov bl,10011010b  
add al,bl
;jump  if AF == 1 

Solution

  • There are no conditional jumps based on AF. The easiest solution, as Peter Cordes said, is to load the flags onto the stack or into AH and branch on that:

    add al, bl    ; some operation that sets AF
    lahf          ; load flags into AH
    test ah, 10h  ; check if AF is set
    jnz afset     ; branch to afset if AF was set
    

    Alternatively, if you are willing to trash AL, you can use aaa on value 00h to check if half carry occured.

    add al, bl    ; some operation that sets AF
    mov al, 0     ; clear AL for testing
    aaa           ; set CF = AF, trash AX
    jc afset     ; branch to afset if AF was set