The signed subtraction with borrowing is rather confusing in x86 assembly. Consider the following words
X = 3A12 H
Y = 4023 H
I wrote the following code
data1 dw 3a12h
data2 dw 4023h
data3 dw ?
;------- THEN --------
mov al, byte ptr data1
mov bl, byte ptr data2
sub al, bl ; 12-23 = EF while carry=1
mov byte ptr data3, al
mov al, byte ptr data1+1
mov bl, byte ptr data2+1
sbb al, bl ; 3A-1(carry from sub)-40=F9 while carry=1
mov byte ptr data3+1, al
Now what is stored in the data3 is F9EF
while the Carry flag is 1. We as humans now that result is negative. In other words, the result is actually -0611 H
. But the computer doesn't know that...
Next, in other instructions it will treat F9EF
as a positive number. Isn't that correct? How x86 know that F9EF
is a negative number?
You may say that the sign bit is 1. OK... Then if I want to use F9EF
as a positive number (or unsigned), how should I tell him?!