beautypg.com

Texas Instruments MSC1210 User Manual

Page 205

background image

Incrementing and Decrementing Registers (INC, DEC)

16-11

8052 Assembly Language

16.10 Incrementing and Decrementing Registers (INC, DEC)

Two instructions, INC and DEC, can be used to increment or decrement the
value of a register, internal RAM, or SFR by 1. These instructions are rather
self-explanatory.

The INC instruction will add 1 to the current value of the specified register. If
the current value is 255, it will overflow back to 0. For example, if the accumula-
tor holds the value 240 and the INC A instruction is executed, the accumulator
is incremented to 241.

INC A

;Increment the accumulator by 1

INC R1

;Increment R1 by 1

INC 40h

;Increment Internal RAM address 40h by 1

The DEC instruction will subtract 1 from the current value of the specified regis-
ter. If the current value is 0, it will underflow back to 255. For example, if the
accumulator holds the value 240 and the DEC A instruction is executed, the
accumulator will be decremented to 239.

DEC A

;Decrement the accumulator by 1

DEC R1

;Decrement R1 by 1

DEC 40h

;Decrement Internal RAM address 40h by 1

Note:

Under some assembly language architectures, the INC and DEC instruc-
tions set an overflow or underflow flag when the register overflows from 255
to 0 or underflows from 0 back to 255, respectively. This is not the case with
the INC and DEC instructions in 8052 assembly language. Neither of these
instructions affects any flags whatsoever.