Texas Instruments MSC1210 User Manual

Page 225

Advertising
background image

Reading and Writing External RAM/Data Memory (MOVX)

16-31

8052 Assembly Language

16.29 Reading and Writing External RAM/Data Memory (MOVX)

The 8052 generally has 128 or 256 bytes of internal RAM that is accessed with
the MOV instruction, as described previously. However, many projects will re-
quire more than 256 bytes of RAM. The 8052 has the ability of addressing up
to 64k of external RAM in the form of additional, off-chip ICs.

The MOVX instruction is used to read from and write to external RAM. The
MOVX instruction has four forms:

1) MOVX A,@DPTR—reads external RAM address DPTR into the

accumulator.

2) MOVX A,@R#—reads external RAM address pointed to by R0 or R1 into

the accumulator.

3) MOVX @DPTR,A—sets external RAM address DPTR to the value of the

accumulator.

4) MOVX @R#,A—sets external RAM address held in R0 or R1 to the value

of the accumulator.

The first two forms move data from external RAM into the accumulator, wheras
the last two forms move data from the accumulator into external RAM.

MOVX with DPTR—when using the forms of MOVX that use DPTR, DPTR is
used as a 16-bit memory address. The 8052 automatically communicates with
the off-chip RAM, obtains the value of that memory address, and stores it in
the accumulator (MOVX A,@DPTR), or writes the accumulator to the off-chip
RAM (MOVX @DPTR,A).

For example, to add 5 to the value contained in external RAM address 2356

H

,

use the following code:

MOV DPTR,#2356h ;Set DPTR to 2356h

MOVX A,@DPTR

;Read external RAM address 2356h into
;accumulator

ADD A,#05h

;Add 5 to the accumulator

MOVX @DPTR,A

;Write new value of accumulator back to
;external RAM 2356h

MOVX with @R0 or @R1—when using the forms of MOVX that use @R0 or
@R1, R0 or R1 will be used to determine the address of external RAM to ac-
cess. These forms of MOVX can only be used to access external RAM ad-
dresses 0000

H

through 00FF

H

, unless actions are taken to control the high

byte of the address, because both R0 and R1 are 8-bit registers.

Advertising