User Manual

23
T89C51AC2
Rev. B 19-Dec-01
7.3 Dual Data Pointer The T89C51AC2 imple ments a s ec ond data pointer f or s peeding up code execution a nd
reducing code size in cas e of intensive usage of ext ernal memory acces ses.
DPTR0 and DPTR1 are seen by the CPU as DPTR and are accessed using the SFR
addres ses 83h and 84h tha t are t he DPH and DPL addresses. Th e DPS b it in AUXR1
register (s ee Figure 5) is used to select whether DPTR is the da ta pointer 0 or the data
pointer 1 (see Figure 7).
Figure 7. Dual Data Pointer Implementation
7.3.1 App l ication Softwa re can tak e advant age of the addition al data po int ers t o both increase speed and
reduc e code size, for ex ampl e, blo c k operations (cop y , c ompare…) are well served by
using one data pointer as a “sourc e” pointer and the other one as a “destination” pointer.
Here after is an example of block move implementation u sing t he two pointers and cod ed
in asse mbler. Th e lat est C co mpiler takes also advant age of this fe ature by prov idi ng
enhanc ed algo rithm libraries.
The INC instruction is a short (2 bytes) and fast (6 mac hine cycle) way to mani pulat e the
DPS bit i n the AUXR1 reg ister. However, note th at t he INC instruction d oes not directly
force the DPS bit to a particular state, but simply toggles it. In simple routines, such as
the block move ex ample, only the fact th at DPS is tog gled in the p roper sequenc e mat-
ters, not its act ual value. In other words, the bloc k move routine w ork s the sam e whether
DPS is '0' or '1 ' on entry.
; ASCII block move using dual data pointers
; Modifies DPTR0, DPTR1, A and PSW
; Ends when encountering NULL character
; Note: DPS exits opposite to the entry state unless an extra INC AUXR1 is
added
AUXR1EQU0A2h
move:movDPTR,#SOURCE ; address of SOURCE
incAUXR1 ; switch data pointers
movDPTR,#DEST ; address of DEST
mv_loop:incAUXR1; switch data pointers
movxA,@DPTR; get a byte from SOURCE
incDPTR; increment SOURCE address
incAUXR1; switch data pointers
movx@DPTR,A; write the byte to DEST
incDPTR; increment DEST address
jnzmv_loop; check for NULL terminator
end_move:
0
1
DPH0
DPH1
DPL0
0
1
DPS
AUXR1.0
DPH
DPL
DPL1
DPTR
DPTR0
DPTR1