All Syllabus

Home About Search Unit 1 Unit 2 Unit 3 Unit 4 Unit 5 Unit 6 Unit 7 Unit 8 Unit 9      

Instruction set of 8051

Data transfer instructions

Arithmetic Group of Instructions

Logical instructions

Logical instructions cont...

Branch instructions


Instruction set of 8051

Data transfer instructions

a. MOV <dest-byte>,<src-byte>-

Function: Move byte variable
Description: The byte variable indicated by the second operand is copied
into the location specified by the first operand. The source byte is not
affected. No other register or flag is affected.

1. mov direct , A
2. mov A, @Ri
3. mov A, Rn
4. mov direct, direct
5. mov A, #data

EX: MOV 30h, A
MOV A,@R0 ; moves the content of memory pointed to by Ro into A
MOV A, R1; ;moves the content of Register R1 to Accumulator A
MOV 20h,30h;moves the content of memory location 30h to 20h
MOV A,#45h;moves 45h to Accumulator A

b. MOV <dest-bit>,<src-bit>

Function: Move bit data
Description: MOV <dest-bit>,<src-bit> copies the Boolean variable indicated
by the second operand into the location specified by the first operand. One of
the operands must be the carry flag; the other may be any directly addressable
bit. No other register or flag is affected.

Example: MOV P1.3,C; moves the carry bit to 3rd bit of port1

C. MOV DPTR,#data16

Function: Load Data Pointer with a 16-bit constant
Description: MOV DPTR,#data16 loads the Data Pointer with the 16-bit constant
indicated. The 16-bit constant is loaded into the second and third bytes of the
instruction. The second byte (DPH) is the high-order byte, while the third byte
(DPL) holds the lower-order byte. No flags are affected.
This is the only instruction which moves 16 bits of data at once.
Example: The instruction,
MOV DPTR, # 4567H
loads the value 4567H into the Data Pointer. DPH holds 45H, and DPL holds 67H.

d. MOVC A,@A+ <base-reg>

Function: Move Code byte
Description: The MOVC instructions load the Accumulator with a code byte or constant
from program memory. The address of the byte fetched is the sum of the original

unsigned 8-bit Accumulator contents and the contents of a 16-bit base register, which
may be either the Data Pointer or the PC. In the latter case, the PC is incremented to
the address of the following instruction before being added with the Accumulator;
otherwise the base register is not altered. Sixteen-bit addition is performed so a carryout
from the low-order eight bits may propagate through higher-order bits. No flags are


f. MOVX <dest-byte>,<src-byte>

Function: Move External

Description: The MOVX instructions transfer data between the Accumulator and a byte
of external data memory, which is why “X” is appended to MOV. There are two types of
instructions, differing in whether they provide an 8-bit or 16-bit indirect address to the
external data RAM.
In the first type, the contents of R0 or R1 in the current register bank provide an 8-bit
address multiplexed with data on P0. Eight bits are sufficient for external I/O expansion
decoding or for a relatively small RAM array. For somewhat larger arrays, any output
port pins can be used to output higher-order address bits. These pins are
controlled by an output instruction preceding the MOVX.
In the second type of MOVX instruction, the Data Pointer generates a 16-bit address.
P2 outputs the high-order eight address bits (the contents of DPH), while P0 multiplexes
the low-order eight bits (DPL) with data. The P2 Special Function Register retains its
previous contents, while the P2 output buffers emit the contents of DPH.
This form of MOVX is faster and more efficient when accessing very large data arrays
(up to 64K bytes), since no additional instructions are needed to set up the output ports.
It is possible to use both MOVX types in some situations. A large RAM array with its
high-order address lines driven by P2 can be addressed via the Data Pointer, or with
code to output high-order address bits to P2, followed by a MOVX instruction using R0
or R1.
Example: An external 256 byte RAM using multiplexed address/data lines is connected
to the 8051 Port 0. Port 3 provides
control lines for the external RAM. Ports 1 and 2 are used for normal I/O. Registers 0
and 1 contain 12H and
34H. Location 34H of the external RAM holds the value 56H. The instruction sequence,
copies the value 56H into both the Accumulator and external RAM location 12H.


PUSH direct

Function: Push onto stack
Description: The Stack Pointer is incremented by one. The contents of the indicated
variable is then copied into the internal RAM location addressed by the Stack Pointer.
No flags are affected.
Example: On entering an interrupt routine, the Stack Pointer contains 09H. The Data
Pointer holds the value 0123H. The
following instruction sequence,
leaves the Stack Pointer set to 0BH and stores 23H and 01H in internal RAM locations
0AH and 0BH,

POP direct

Function: Pop from stack.
Description: The contents of the internal RAM location addressed by the Stack Pointer
is read, and the Stack Pointer is decremented by one. The value read is then
transferred to the directly addressed byte indicated. No flags are affected.
Example: The Stack Pointer originally contains the value 32H, and internal RAM
locations 30H through 32H contain the values 20H, 23H, and 01H, respectively. The
following instruction sequence,
leaves the Stack Pointer equal to the value 30H and sets the Data Pointer to 0123H.