我正在阅读Richard Detmer 的《汇编语言》一书。
第一章说:
A borrow occurs in the subtraction a - b when b is larger than a as unsigned numbers. Computer hardware can detect a borrow in subtraction by looking at whether a carry occurred in the corresponding addition. If there is no carry in the addition, then there is a borrow in the subtraction. If there is a carry in the addition, then there is no borrow in the subtraction.
进位标志是EFL
寄存器的第 0 位。
假设我们要执行 195D - 618D = -423D 作为减法运算。有借位,因此不应设置进位标志。
以下 asm 代码编译并运行,但在 之后sub rax, 618
,确实设置了进位标志。
相应的加法将是 00C3h + FD96h,这不涉及进位,因为最终的成对加法是 0 + F,没有进位,因此最终成对加法没有进位。
.DATA
number QWORD 195
sum QWORD ?
.CODE
main PROC
mov rax, number ; 195 to RAX
sub rax, 618 ; subtract 618
;at this point, however, the carry flag is indeed set to 1. Why is this?
mov sum, rax ; sum to memory
mov rax, 0 ; return code
ret ; exit to operating system
main ENDP
END
我不清楚这怎么可能。
任何帮助将不胜感激。