The SBB instruction

Subtract with borrow.

The SBB instruction format

InstructionDescription
SBB AL, imm8Subtract with borrow imm8 from AL.
SBB AX, imm16Subtract with borrow imm16 from AX.
SBB reg/mem8, imm8Subtract with borrow imm8 from reg/mem8.
SBB reg/mem16, imm16Subtract with borrow imm16 from reg/mem16.
SBB reg/mem16, imm8Subtract with borrow sign-extended imm8 from reg/mem16.
SBB reg/mem8, reg8Subtract with borrow reg8 from reg/mem8.
SBB reg/mem16, reg16Subtract with borrow reg16 from reg/mem16.
SBB reg8, reg/mem8Subtract with borrow reg/mem8 from reg8.
SBB reg16, reg/mem16Subtract with borrow reg/mem16 from reg16.

Adds the source operand (the second operand) and the carry flag (CF) and subtracts the result from the destination operand (the first operand). The result of the subtraction is stored in the destination operand. The destination operand can be a register or a memory location; the source operand can be an immediate value, a register or a memory location. However, two memory operands cannot be used in one instruction. The state of the CF flag represents a borrow from the previous subtraction.

Instruction sbb is usually executed as part of a multi-byte or multi-word subtraction, in which the sub instruction is followed by sbb.

Usage example

In the following example we perform a 32-bit subtraction: 65536 - 1 = 65535. The minuend (65536) is stored in the DX:AX pair (DX=0001h, AX=0000h) and the subtrahend (1) is stored in the BX:CX pair (BX=0000h, CX=0001h).

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

code segment public        ; Start of the code segment
    assume cs:code

    main proc              ; Start of the main procedure
        mov     dx, 1      ; Copy the value 0000 0000 0000 0001 into the dx register
        mov     ax, 0      ; Copy the value 0000 0000 0000 0000 into the ax register

        mov     bx, 0      ; Copy the value 0000 0000 0000 0000 into the bx register
        mov     cx, 1      ; Copy the value 0000 0000 0000 0001 into the cx register

        sub     ax, cx     ; Subtract the value in cx from the ax register
        sbb     dx, bx     ; Subtract bx from the dx register with borrow

        mov     ax, 4C00h  ; Copy the process termination function number into ah and the value into al
        int     21h        ; Call the interrupt
    main endp              ; End of the main procedure

code ends                  ; End of the code segment
end main                   ; End of file. The main procedure is the entry point

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".

Processor status flags

CF
Yes
PF
Yes
AF
Yes
ZF
Yes
SF
Yes
TF
No
IF
No
DF
No
OF
Yes