Texas Instruments MSC1210 User Manual

Page 224

Advertising
background image

Setting the Data Pointer DPTR (MOV DPTR)

16-30

16.28 Setting the Data Pointer DPTR (MOV DPTR)

The next few instructions use the data pointer (DPTR), the only 16-bit register
in the 8052. DPTR is used to point to a RAM or ROM address when used with
the following instructions that are explained.

As described earlier, DPTR is really made up of two SFRs: DPH and DPL
which hold the high and low bytes, respectively, of the 16-bit data pointer. How-
ever, when DPTR is used to access memory, the 8052 will treat DPTR as a
single address.

To set the DPTR to a specific address, the MOV DPTR instruction is used. This
instruction sets both DPH and DPL in a single instruction. However, DPTR can
still be modified by accessing DPH and DPL directly, as illustrated in the follow-
ing examples:

MOV DPTR,#1234h

;Sets DPTR to 1234h

MOV DPTR,#0F123h ;Sets DPTR to F123h

MOV DPH,#40h

;Sets DPTR high−byte to 40h (DPTR now 4023h)

MOV DPL,#56h

;Sets DPTR low−byte to 56h (DPTR now 4056h)

As shown, the first two instructions set DPTR first to 1234

H

and then to F123

H

.

The next example sets DPH to 40

H

, leaving the DPTR low byte unchanged.

Changing DPH to 40

H

will result in DPTR being equal to 4023

H

because the low

byte is still 23

H

from the previous example. Finally, we change the low byte to 56

H

,

leaving the high byte unchanged. Setting the low byte to 56

H

will leave the DPTR

with a value of 4056

H

because the high byte was set to 40

H

in the previous exam-

ple.

In other words, MOV DPTR,#1567h is the same as MOV DPH,#15h and MOV
DPL,#67h. The advantage to using MOV DPTR is that it uses only three bytes
of memory and two instruction cycles, whereas the other method requires six
bytes of memory and four instruction cycles.

Advertising