这是从 Visual Studio 获得的打印屏幕,显示了 VS2019 和英特尔手册之间的明显矛盾。
您将在下面找到此 x86 项目的相应代码:
.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