0% found this document useful (0 votes)
25 views34 pages

Unit 5-Data Transfer Instruction

The document describes the different types of instructions in the 8051 instruction set including data transfer, arithmetic, logical, boolean, program branching and other instructions. It provides examples of how each instruction works by showing the values before and after execution.

Uploaded by

G.Akshaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views34 pages

Unit 5-Data Transfer Instruction

The document describes the different types of instructions in the 8051 instruction set including data transfer, arithmetic, logical, boolean, program branching and other instructions. It provides examples of how each instruction works by showing the values before and after execution.

Uploaded by

G.Akshaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Instruction Set

8051 has about 111 instructions.


Grouped into the following categories

Instruction Set

Data Boolean Program


Arithmetic Logical Transfer Variable Branching
Instructions Instructions Instructions Instructions Instructions
Instruction Set
Note
The following names for register, data, address and variables
are used while writing the instructions.
 A: Accumulator
 B: "B" register
 C: Carry bit
 Rn: Register R0 - R7 of the currently selected register
bank
 Direct: 8-bit internal direct address for data. The data
could be in lower 128bytes of RAM (00 - 7FH) or it
could be in the special function register (80 - FFH).
Instruction Set
Note
@Ri: 8-bit external or internal RAM address available in
register R0 or R1. This is used for indirect addressing mode.
#data8: Immediate 8-bit data available in the instruction.
#data16: Immediate 16-bit data available in the instruction.
Addr11: 11-bit destination address for short absolute jump.
Used by instructions AJMP & ACALL. Jump range is
2kbyte (one page).
Addr16: 16-bit destination address for long call or long
jump.
Rel: 2's complement 8-bit offset (one - byte) used for short
jump (SJMP) and all conditional jumps.
bit: Directly addressed bit in internal RAM or SFR
Data Transfer Instructions
Data Transfer Instructions are used to transfer or copy the data
Between

Registers

Internal Memory

External Program Memory

External Data Memory


MOV A,Rn
 Copy the data from Register Rn to Accumulator

 Example

Mov A,R3 : Copy the Data from R3 to Accumulator

Before Execution

Assume R3=50H , A=60H

After Execution

R3=50H ,A=50H
MOV A,direct
 Copy the data from the addressed location (direct) to the
accumulator
 Example
Mov A, 32H ; Copy the data from the internal memory
location 32H to Accumulator
Before Execution
Assume A=50H ,Memory Location 32H=60H
After Execution
A=60H , Memory Location 32H=60H
MOV A,@Ri
 Copy the data to accumulator from the location specified in
Register Ri
Example
Mov A,@R0; Copy the data from the location specified by Ro to
Accumulator
Before Execution
Assume A=50H , R0=32H ,Memory Location 32H=60H
After Execution
A=60H , R0=32H ,Memory Location 32H=60H
MOV A,#data

 Moves the immediate data to the accumulator


Example
Mov A,#40H; Copy the data 40H to the Accumulator
Before Execution
Assume A=50H
After Execution
A=40H
MOV Rn,A

 Copies the accumulator content to the register (Rn)


 Example
Mov R3,A : Copy the Data from Accumulator to Register R3

Before Execution

Assume R3=50H , A=60H

After Execution

R3=60H , A=60H
MOV Rn,direct

 Copy the data from the addressed location (direct) to the Register Rn
Example
Mov R0, 32H ; Copy the data from the internal memory location
32H to register R0
Before Execution
Assume A=50H ,Memory Location 32H=60H
After Execution
A=60H , Memory Location 32H=60H
MOV Rn,#data

 Copy the immediate data to the register


Example
Mov R2,#40H; Copy the data 40H to the Register R2
Before Execution
Assume R2=50H
After Execution
R2=40H
MOV direct,A
 Copy the accumulator content to addressed location (direct)
Example
Mov 32H, A ; Copy the data from the Accumulator to internal
memory location 32H
Before Execution
Assume Memory Location 32H=60H , A=50H
After Execution
Memory Location 32H=50H , A=50H
MOV direct,Rn
 Copy the Register(Rn) content to addressed location (direct)
Example
Mov 32H, R3 ; Copy the data from register R3 to the internal
memory location 32H
Before Execution
Assume Memory Location 32H=60H, R3=50H
After Execution
Memory Location 32H=50H , R3=50H

MOV direct,@Ri

 Copies the data from the memory location specified by the


register Ri to memory location (direct)
 Example
Mov 32H, @R0 ; Copy the data from the location specified
by register R0 to the internal memory location 32H
Before Execution
Assume Memory Location 32H=60H, R0=50H ,
50H=43H
After Execution
Memory Location 32H=50H , R3=50H
MOV directD,directS

 Copy the data from the source location (directs) to destination


location (directD)
Example
Mov 32H,42H ; Copy the data from the internal memory location
42H to internal memory location 32H
Before Execution
Assume Memory Location 32H=60H , 42H=50H
After Execution
Memory Location 32H=50H , 42H=50H
MOV direct,#data
 Copy the 8-bit data to addressed location (direct)
Example
Mov 32H,#41H; Copy the data 41H to internal memory
location 32H
Before Execution
Assume Memory Location 32H=60H
After Execution
Memory Location 32H=41H
MOV @Ri,A
 Copy the data from accumulator to the location specified in
Register Ri
Example
Mov @R0,A ; Copy the data from the Accumulator to the
location specified by Ro
Before Execution
Assume A=50H , R0=32H ,Memory Location 32H=60H
After Execution
A=50H , R0=32H ,Memory Location 32H=50H
MOV @Ri,direct

 Copies the data from memory location (direct) to the


memory location specified by the register Ri
 Example
Mov @R0, 32H, ; Copy the data from the internal memory location
32H to the location specified by register R0
Before Execution
Assume Memory Location R0=50H , 50H=43H, 32H=60H
After Execution
Memory Location R0=50H, 50H=60H , 32H=60H
MOV @Ri,#data
 Copies the 8-bit data to the memory location specified by the
register Ri
 Example
Mov @R0,#32H, ; Copy the data 32H to the location
specified by register R0
Before Execution
Assume Memory Location R0=50H , 50H=43H
After Execution
Memory Location R0=50H, 50H=32H
MOV DPTR,#data

 Moves the 16 bit data to the register DPTR

 Example

Mov DPTR, #4100H; Moves the data 4100H to the DPTR register

Before Execution

Assume DPTR=4000H

After Execution

DPTR=4100H
MOVC A,@A+DPTR
 Copies the code byte relative to the DPTR
(address=A+DPTR) to the accumulator
Example
MOVC A,@A+DPTR
Before Execution
Assume A =30H, DPTR =1125H, A+DPTR=1155H (30H + 1125H),
Code memory 1155H= A5H
After Execution
A= A5H
MOVC A,@A+PC

 Copies the code byte relative to the PC (address=A+PC) to


the accumulator
Example
MOVC A,@A+PC
Before Execution
Assume A =30H, PC =1125H, A+PC=1155H (30H + 1125H),
Code memory 1155H= A5H
After Execution
A= A5H
MOVX A,@Ri

 Copy the data to accumulator from the external memory


location specified in Register Ri
Example
Movx A,@R0; Copy the data from the external memory location
specified by Ro to Accumulator
Before Execution
Assume A=50H , R0=32H ,External Data Memory
Location 0032H=60H
After Execution
A=60H , R0=32H ,Memory Location 0032H=60H
MOVX A,@DPTR
 Copy the data to accumulator from the external memory
location specified in DPTRRegister
Example
Movx A,@DPTR; Copy the data from the external memory
location specified by DPTR to Accumulator
Before Execution
Assume A=50H , DPTR=4100H
External Data Memory Location 4100H=60H
After Execution
A=60H , DPTR=4100H
External Data Memory Location 4100H=60H
MOVX @Ri,A
 Copy the data from accumulator to the external memory
location specified by Register Ri
Example
Movx @R0 ,A; Copy the data from Accumulator to the external
memory location specified by Ro
Before Execution
Assume R0=32H ,
External Data Memory Location 0032H=60H ,A=50H
After Execution
R0=32H , External Data Memory Location 0032H=50H
MOVX @DPTR,A
 Copy the data from accumulator to the external memory
location specified by DPTR Register
Example
Movx @DPTR,A; Copy the data from Accumulator to the
external memory location specified by DPTR
Before Execution
Assume DPTR=4100H , 4100H=40H,A=50H
After Execution
DPTR=4100H , 4100H=50H, A=50H
PUSH direct
 The PUSH instruction increments the stack pointer and stores
the value of the specified byte operand at the internal RAM
address indirectly referenced by the stack pointer. No flags are
affected by this instruction.
Example
PUSH A; Increments the stack pointer and stores the value
of accumulator at the internal RAM address indirectly
referenced by the stack pointer
Before Execution
Assume SP=4100H , A=40H
After Execution
SP=4101H , 4101H=40H
POP direct
 The POP instruction reads a byte from the address indirectly
referenced by the SP register. The value read is stored at the
specified address and the stack pointer is decremented. No
flags are affected by this instruction.
Example
POP A; Reads a byte from the address indirectly referenced
by the SP register. The value read is stored at Accumulator and
the stack pointer is decremented.
Before Execution
Assume SP=4101H , 4101H= 55H , A=40H
After Execution
A=55H , SP=4100H
XCH A,Rn
 Exchanges the register content with the accumulator
Example
Xch A,R2; Exchanges the R2 register content with the
accumulator
Before Execution
Assume A=50H ,R2=45H
After Execution
A=45H ,R2=50H
XCH A,direct

Exchanges data from the addressed location (direct)


with the accumulator
Example
Xch A,40H; Exchanges data available in the memory
location 40H with the accumulator data
Before Execution
Assume A=50H ,40H=45H
After Execution
A=45H , 40H=50H
XCH A,@Ri

 Exchanges data from the memory location specified by the


register Ri with the accumulator content
Example
Xch A,@R0; Exchanges data from the location specified by Ro with
Accumulator Data
Before Execution
Assume A=50H ,R0=40H, 40H=45H
After Execution
A=45H , R0=40H, 40H=50H
XCHD A,@Ri
 exchanges the low-order nibble of the accumulator with the
low-order nibble of the data accessed indirectly through R0
or R1. The high-order nibbles of each operand are not
affected
Example
XCHD A, @R1; exchanges the low-order nibble of the accumulator with the
low-order nibble of the data available in the indirect address R1
Before Execution
Assume A=50H ,R1=40H, 40H=45H
Low order nibble of A=0 and Low order nibble of the data
available in the location 40H=5
After Execution
A=55H , R0=40H, 40H=40H

You might also like