Hardware manual

The 8051 Instruction Set
Atmel 8051 Microcontrollers Hardware Manual 1-9
4316A–8051–01/04
repeated for location 2DH. The CJNE instruction (Compare and Jump if Not Equal) is a
loop control that will be described later.
The loop is executed from LOOP to CJNE for R1 = 2EH, 2DH, 2CH and 2BH. At that
point the digit that was originally shifted out on the right has propagated to location 2AH.
Since that location should be left with 0s, the lost digit is moved to the Accumulator.
1.6 External RAM Table 1-7 shows a list of the Data Transfer instructions that access external Data Mem-
ory. Only indirect addressing can be used. The choice is whether to use a one-byte
address, @Ri, where Ri can be either R0 or R1 of the selected register bank, or a two-
byte address, @DPTR. The disadvantage to using 16-bit addresses if only a few
Kbytes of external RAM are involved is that 16-bit addresses use all 8 bits of Port 2 as
address bus. On the other hand, 8-bit addresses allow one to address a few Kbytes of
RAM, as shown in Table 1-7, without having to sacrifice all of Port 2.
All of these instructions execute in 2 µs, with a 12 MHz clock (and X1 mode).
Note that in all external Data RAM accesses, the Accumulator is always either the desti-
nation or source of the data.
The read and write strobes to external RAM are activated only during the execution of a
MOVX instruction. Separately these signals are inactive, and in fact if they’re not going
to be used at all, their pins are available as extra I/O lines.
1.7 Lookup Tables Table 1-8 shows the two instructions that are available for reading lookup tables in Pro-
gram Memory. Since these instructions access only Program Memory, the lookup tables
can be read, not updated. The mnemonic is MOVC for “move constant”.
If the table access is to external Program Memory, then the read strobe is PSEN
.
The first MOVC instruction in Table 1-8 can accommodate a table of up to 256 entries,
numbered 0 through 255. The number of the desired entry is loaded into the Accumula-
tor, and the Data Pointer is set up to point to beginning of the table. Then
MOVC A, @A + DPTR
copies the desired table entry into the Accumulator.
The other MOVC instruction works the same way, except the Program Counter (PC) is
used as the table base, and the table is accessed through a subroutine. First the num-
ber of the desired entry is loaded into the Accumulator, and the subroutine is called:
Table 1-7. Data Transfer Instructions that Access External Data Memory Space
Address Width Mnemonic Operation
Execution Time
@ 12MHz (µs)
8 bits MOVX A, @Ri
Read external
RAM @ Ri
2
8 bits MOVX @ Ri, A
Write external
RAM @ Ri
2
16 bits MOVX A, @ DPTR
Read external
RAM @ DPTR
2
16 bits MOVX @ DPTR, A
Write external
RAM @ DPTR
2