The SBB instruction
Subtract with borrow.
The SBB instruction format
| Instruction | Description |
|---|---|
| SBB AL, imm8 | Subtract with borrow imm8 from AL. |
| SBB AX, imm16 | Subtract with borrow imm16 from AX. |
| SBB reg/mem8, imm8 | Subtract with borrow imm8 from reg/mem8. |
| SBB reg/mem16, imm16 | Subtract with borrow imm16 from reg/mem16. |
| SBB reg/mem16, imm8 | Subtract with borrow sign-extended imm8 from reg/mem16. |
| SBB reg/mem8, reg8 | Subtract with borrow reg8 from reg/mem8. |
| SBB reg/mem16, reg16 | Subtract with borrow reg16 from reg/mem16. |
| SBB reg8, reg/mem8 | Subtract with borrow reg/mem8 from reg8. |
| SBB reg16, reg/mem16 | Subtract 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 .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)".