Setting the Data Pointer DPTR (MOV DPTR)

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 1234H and then to F123H. The next example sets DPH to 40H, leaving the DPTR low byte unchanged. Changing DPH to 40H will result in DPTR being equal to 4023H because the low byte is still 23H from the previous example. Finally, we change the low byte to 56H, leaving the high byte unchanged. Setting the low byte to 56H will leave the DPTR with a value of 4056H because the high byte was set to 40H 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.

16-30

Page 224
Image 224
Texas Instruments MSC1210 manual Setting the Data Pointer Dptr MOV Dptr