<<< ADC Instruction, Cont, | Index | SBB Instruction, Integer Subtraction with Borrow >>> |
The following fragment adds two 8-bit integers (FFh + FFh), producing a 16-bit sum in DL:AL, which is 01h:FEh.
mov dl, 0 mov al, 0FFh add al, 0FFh ; AL = FEh, CF = 1 adc dl, 0 ; DL += CF, add "leftover" carry
Similarly, the following instructions add two 32-bit integers (FFFFFFFFh + FFFFFFFFh).
The result is a 64-bit sum in EDX:EAX, 0000000lh:FFFFFFFEh,
mov edx, 0 mov eax, 0FFFFFFFFh add eax, 0FFFFFFFFh adc edx, 0 ; EDX += CF, add "leftover" carry
The following instructions add two 64-bit numbers received in EBX:EAX and EDX:ECX:
The result is returned in EBX:EAX.
Overflow/underflow conditions are indicated by the Carry flag.
add eax, ecx ; add low parts EAX += ECX, set CF adc ebx, edx ; add high parts EBX += EDX, EBX += CF ; The result is in EBX:EAX ; NOTE: check CF or OF for overflow (*)
The 64-bit subtraction is also simple and similar to the 64-bit addition:
sub eax, ecx ; subtract low parts EAX -= ECX, set CF (borrow) sbb ebx, edx ; subtract high parts EBX -= EDX, EBX -= CF ; The result is in EBX:EAX ; NOTE: check CF or OF for overflow (*)
_____________
(*) The Carry flag CF is normally used for unsigned arithmetic.
The Overflow flag OF is normally used for signed arithmetic.
<<< ADC Instruction, Cont, | Index | SBB Instruction, Integer Subtraction with Borrow >>> |