<<< ADC Instruction, Cont,     Index     SBB Instruction, Integer Subtraction with Borrow >>>

17. ADC Examples


  1. 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
    

     

  2. 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
    

     

  3. The following instructions add two 64-bit numbers received in EBX:EAX and EDX:ECX:

        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 (*)
    

     

  4. 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 (*)
    

<<< ADC Instruction, Cont,     Index     SBB Instruction, Integer Subtraction with Borrow >>>