ADD, SUB 

Adding and Subtracting Integers:

The ADD, INC (Increment), SUB, and DEC (Decrement) instructions operate on 8 and 16-bit values on the 8086–80286 processors, and on 8-, 16-, and 32-bit values on the 80386/486 processors. They can be combined with the ADC and SBB instructions to work on 32-bit values on the 8086 and 64-bit values on the 80386/486 processors.

These instructions have two requirements:
	1.	If there are two operands, only one operand can be a memory operand.
	2.	If there are two operands, both must be the same size.

To meet the second requirement, the PTR operator can be used to force an operand to the size required.
For example, if Buffer is an array of bytes and BX points to an element of the array, you can add a word from Buffer with:

        add     ax, WORD PTR Buffer[bx] ; Add word from byte array

The next examples shows 8-bit signed and unsigned addition and subtraction.

8-bit signed and unsigned addition
        .DATA
MEM8    BYTE    39
        .CODE
        
; ADDITION
                         ;                    SIGNED        UNSIGNED
        MOV     AL, 26   ; START WITH REGISTER   26 (1AH)      26
        INC     AL       ; INCREMENT           +  1 (01H)    +  1
        ADD     AL, 76   ; ADD IMMEDIATE       + 76 (4CH)    + 76
                         ;                     ----           ----
                         ;                      103 (67H)     103
        ADD     AL, MEM8 ; ADD MEMORY            39 (27H)    + 39
                         ;                     ----           ----
        MOV     AH, AL   ; COPY TO AH          -114 (8EH)     142 (8EH)
                                           (Overflow flag=1)
        ADD     AL, AH   ; ADD REGISTER                     + 142 (8EH)
                         ;                                    ----
                         ;                                     28 (1CH)
                                                           (Carry Flag=1)


8-bit signed and unsigned subtraction
        .DATA
MEM8    BYTE    122
        .CODE
; SUBTRACTION
                         ;                   SIGNED          UNSIGNED
        MOV     AL, 95   ; LOAD REGISTER         95 (5FH)       95
        DEC     AL       ; DECREMENT             -1 (01H)       -1
        SUB     AL, 23   ; SUBTRACT IMMEDIATE   -23 (17H)       -23
                         ;                     ----            ----
                         ;                       71 (47H)       71
        SUB     AL, MEM8 ; SUBTRACT MEMORY     -122 (7AH)     -122
                         ;                     ----            ----
                         ;                      -51 (CDH)       205 (CDH)
                                                             (Carry Flag=1)

        MOV     AH, 119  ; LOAD REGISTER        119 (77H)
        SUB     AH, AL   ; SUBTRACT REGISTER    -51 (CDH)
                         ;                     ----
                         ;                       86 (BAH) 
                                            (Overflow flag=1)