The ADD instruction

Addition.

The ADD instruction format

InstructionDescription
ADD AL, imm8Add imm8 to AL.
ADD AX, imm16Add imm16 to AX.
ADD reg/mem8, imm8Add imm8 to reg/mem8.
ADD reg/mem16, imm16Add imm16 to reg/mem16.
ADD reg/mem16, imm8Add sign-extended imm8 to reg/mem16.
ADD reg/mem8, reg8Add reg8 to reg/mem8.
ADD reg/mem16, reg16Add reg16 to reg/mem16.
ADD reg8, reg/mem8Add reg/mem8 to reg8.
ADD reg16, reg/mem16Add reg/mem16 to reg16.

Adds the destination operand (first operand) and the source operand (second operand), and then 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.

The add instruction performs integer addition. It computes the result for both signed and unsigned integer operands and sets the OF and CF flags to indicate a carry (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
        add     al, bl     ; Add the value of the bl register to 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)".

Second example: fast multiplication by 10

The following example demonstrates fast multiplication of a number by 10 using the SHL instruction and addition.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    number dw 7
    result dw ?
data ends

code segment public           ; Start of the code segment
    assume ds:data, cs:code

    main proc                 ; Start of the main procedure
        mov     ax, seg data  ; Get the data segment address and store it in ax
        mov     ds, ax        ; Pass the data segment address from ax to ds

        mov     ax, number    ; Copy the value of the variable number into the ax register
        mov     bx, ax        ; Save the value of the ax register in the bx register
        shl     ax, 1         ; AX := AX * 2
        shl     bx, 3         ; BX := BX * 8
        add     ax, bx        ; AX := AX + BX
        mov     result, ax    ; Save the value of the ax register in the variable result

        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