The INC and DEC instructions

Increment and decrement by 1.

The INC instruction format

InstructionDescription
INC reg/mem8Increment reg/mem8 by 1.
INC reg/mem16Increment reg/mem16 by 1.

Adds 1 to the destination operand while preserving the state of the CF flag. The destination operand can be a register or a memory location. This instruction allows the loop counter to be updated without disturbing the CF flag. Use the add instruction with an immediate operand equal to 1 to perform an increment operation that updates the CF flag.

The DEC instruction format

InstructionDescription
DEC reg/mem8Decrement reg/mem8 by 1.
DEC reg/mem16Decrement reg/mem16 by 1.

Subtracts 1 from the destination operand while preserving the state of the CF flag. The destination operand can be a register or a memory location. This instruction allows the loop counter to be updated without disturbing the CF flag. (To perform a decrement operation that updates the CF flag, use the sub instruction with an immediate operand equal to 1.)

Usage example

In this example the cx register contains 2. Executing inc cx increments it to 3, then dec cx is executed twice, which decrements it to 1.

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     cx, 2      ; Copy the value 2 into the cx register

        inc     cx         ; Increase the value of the cx register by 1
        dec     cx         ; Decrease the value of the cx register by 1
        dec     cx         ; Decrease the value of the cx register by 1

        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
No
PF
Yes
AF
Yes
ZF
Yes
SF
Yes
TF
No
IF
No
DF
No
OF
Yes