Shouldn't the AF (auxiliary flag) be set in the example shown below after the execution of the instruction `add al, '3'`?

124 Views Asked by At

This is a print screen obtained from Visual Studio showing the apparent contradiction between VS2019 and the Intel's manuals.

enter image description here

Below you'll find the corresponding code for this x86 project:

.486
.model flat,stdcall
.stack 4096
ExitProcess proto, dwExitCode:dword

.code
main proc
    mov ah,0
    mov al,'6' ; AX = 0036h
    add al,'3' ; AX = 0069h                     ; Section 3.4.3.1 of Volume 1 of Intel's docs says the following regarding
                                                ; the AF (auxiliary flag):
                                                ;
                                                ; "Set if an arithmetic operation generates a carry or a borrow out of bit 3
                                                ;  of the result; cleared otherwise. This flag is used in binary-coded
                                                ;  decimal (BCD) arithmetic."
                                                ;
                                                ; Shouldn't the instruction above (add al, '3') set the AF flag to 1?
                                                ; If we look at the corresponding bits affected by this instruction we have:
                                                ;
                                                ;       7654 3210 >> Bit numbers
                                                ;       ---- ----
                                                ; 36h   0011 0110
                                                ; 33h   0011 0011
                                                ; AL    0110 1001   which shows that bit 3 had a carry from bit 2. Therefore,
                                                ;                   bit number 4 in the EFLAGS register (AF flag) should be
                                                ;                   set to 1. But that's not what the EFL shows below in the
                                                ;                   Registers window.
                                                ;
                                                ; What am I missing?

    aaa ; AX = 0069h (ASCII adjust result)

    invoke ExitProcess,0                        
main endp
end main
0

There are 0 best solutions below