The INC and DEC instructions
Increment and decrement by 1.
The INC instruction format
| Instruction | Description |
|---|---|
| INC reg/mem8 | Increment reg/mem8 by 1. |
| INC reg/mem16 | Increment 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
| Instruction | Description |
|---|---|
| DEC reg/mem8 | Decrement reg/mem8 by 1. |
| DEC reg/mem16 | Decrement 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 .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)".