The SUB instruction

Subtraction.

The SUB instruction format

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

Subtracts the second operand (source operand) from the first operand (destination operand) and stores the result 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. (Two memory operands, however, cannot be used in the same instruction.) When an immediate value is used as an operand, it is sign-extended to the length of the destination operand format.

Instruction sub performs integer subtraction. It computes the result for both signed and unsigned integer operands and sets the OF and CF flags to indicate an overflow in the signed or unsigned result, respectively. The SF flag indicates the sign of the signed result.

Usage example

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     al, 18     ; Copy the value 18 into the al register
        mov     bl, 4      ; Copy the value 4 into the bl register
        sub     al, bl     ; Subtract the value in the bl register from the al register

        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