Anda di halaman 1dari 9

Subject:

Microcontroller &
Interfacing

Title:
8051 Data Transfer Instructions

Experiment No.
04

4.8

Rev. No.

DOC. CODE
AITS/ECD/EXPT

DATE:

1.00

Aim: - To Study 8051 data transfer instructions.


Theory: In data transfer instructions data stored at source address is moved (actually copied) to a
destination address.
Five types of Opcodes are used to move data:
1. MOV
2. MOVX
3. MOVC
4. PUSH, POP and
5. XCH
6.
For internal RAM and working register (Rr) opcode MOV is used, for external RAM opcode MOVX
is used. Opcode MOVC is used for internal & external ROM. Some exchange instructions are also
available under opcode XCH. Two instructions are available to transfer carry flag to/from any bit of bit
addressable area of internal RAM & any bit of bit addressable SFR. Detailed description is given below.
Data transfer instructions except those involving carry flag and PSW affect no flags.
1. MOV Instructions: Mnemonics
MOV A,Rr

Function
Rr A

MOV A,add

(add) A

MOV A,@RP

(RP) A

MOV A,#n

n A

MOV R,A

A Rr

MOV Rr,add

(add) Rr

MOV Rr,#n

n Rr

MOV add,A

A (add)

MOV add,Rr

Rr (add)

MOV add,@RP

RP (add)

Description
Copy data from register Rr to
Accumulator.
Copy data from given memory
location to the accumulator.
Copy data from memory location to
accumulator, whose address is given
by RP.
Copy immediate data n to
accumulator.
Copy data from Accumulator to
register Rr.
Copy data from given memory
location to register Rr.
Copy immediate data n to register Rr.
Copy data from the accumulator to
given memory location.
Copy data from register Rr to
given memory location.
Copy data from address given by RP
to given memory location.

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

Bytes
1

Cycles
1

Subject:
Microcontroller &
Interfacing

Title:
8051 Data Transfer Instructions

Experiment No.
04

n (add)

MOV add1,add2

(add2) (add1)

MOV @RP,A

A (RP)

MOV @RP,add

(add) (RP)

MOV @RP,#n

#n (RP)

MOV DPTR,#nn

nn DPTR

Rev. No.

DOC. CODE
AITS/ECD/EXPT

DATE:

MOV add,#n

4.8

Copy immediate data n to given


memory location.
Copy data from given memory
location 2 to given memory location
1.
Copy data from the accumulator to
memory location address given by
RP.
Copy data from the given memory
location to the memory location
address given by RP.
Copy immediate data n to the
memory location address given by
RP.
Load immediate 16-bit data in DPTR
register.

1.00
3

2. MOVC Instructions: Mnemonics


MOVC A,@(A+PC)

Function
(A+PC) A

MOVC A,@(A+DPTR)

(A+DPTR) A

Description
Copy the code byte, found at
the address (A+PC) to
Accumulator
Copy the code byte, found at
the address (A+DPTR),to
Accumulator

Bytes
1

Cycles
2

Bytes
1

Cycles
2

3. MOVX Instructions: Mnemonics


MOVX A,@DPTR

Function
(DPTR) A

MOVX @DPTR,A

A (DPTR)

MOVX A,@RP

(RP) A

MOVX @RP,A.

A (RP)

Description
Copy the contents of the external RAM
address in DPTR to Accumulator.
Copy data from the Accumulator
to external RAM address in DPTR.
Copy the contents of the external RAM
address in RP to Accumulator.
Copy data from the Accumulator
to external RAM address in RP.

4. PUSH & POP Instructions: Mnemonics


POP add

Function
(SP) (add)

Description
Copy the data from internal RAM

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

Bytes
2

Cycles
2

Subject:
Microcontroller &
Interfacing
Experiment No.
04

PUSH add

Title:
8051 Data Transfer Instructions

Rev. No.

DOC. CODE
AITS/ECD/EXPT

DATE:

(add) (SP)

4.8

1.00

address contained in SP to add;


Decrement SP
Increment SP; copy the data in add to
the internal RAM address contained in
SP

5. XCH Instructions: Mnemonics


XCH A,Rr

Function
A Rr

XCH A,add

A (add)

XCH A,@RP

A (RP)

XCHD A,@RP

Alsn (RP)lsn

Description
Exchange data bytes between register Rr
and accumulator.
Exchange data bytes between add and
accumulator.
Exchange data bytes between
accumulator & contents of memory
location (address given by RP).
Exchange lower nibble between
Accumulator & contents of memory
location (address given by RP).

Bytes
1

Cycles
1

6. Other Instructions: Mnemonics Function Description


Bytes Cycles
MOV b,C
Cb
Copy the C flag to the addressed bit.
2
2
MOV C,b
bC
Copy the addressed bit to the C flag
2
1
Notations used: add
:Address of the internal RAM from 00H to FFH (including SFR address)
n
:Any immediate 8 bit number from 00H to FFH.
nn
:Any immediate 16 bit number from 0000H to FFFFH.
Rr
:Any of the eight registers from R0 to R7 in currently selected bank.
Rp
:Either of pointing registers R0 or R1 in currently selected bank.
( ) :- Contents of the location inside the parentheses.
b
:Addressable bit in internal RAM or a SFR.
C
:The Carry flag.
lsn
:Least significant nibble.
Note: - When PSW address is used it may affect the flags. MOV C,B instruction may affect carry flag.
Otherwise no flags are affected in this group of instructions.

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

Subject:
Microcontroller &
Interfacing
Experiment No.
04

Title:
8051 Data Transfer Instructions

DATE:

DOC. CODE
AITS/ECD/EXPT

4.8

Rev. No.

1.00

EXERCISE: 1. Write a program to copy Immediate data AAH into registers R4, R5, & R6 of bank 2 using at least
four different methods.
2. Place the number 3Bh in internal RAM locations 30h to 32h.
3. Exchange the contents of the SP and the PSW.
4. Copy the byte at internal RAM address 27h to external RAM address 27h.
5. Set timer 1 to A23Dh.
6. Copy the data in external RAM locations 0123h to TL0 and the data in external RAM location 0234h
to TH0.
7. Set the SP register to 07h and PUSH the SP register on the stack; predict what number is PUSHed to
address 08h.
PROGRAM
org 00h
mov sp,#07h
push 81h
end
OUTPUT:

8. Rotate the bytes in registers R0 to R3: copy the data in R0 to R1, R1 to R2,
R0.
org 00h
MOV R0,#10H
MOV R1,#11H
MOV R2,#12H
MOV R3,#13H
MOV A,R3
XCH A,R0
XCH A,R1
XCH A,R2
ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

R2 to R3, and R3 to

Subject:
Microcontroller &
Interfacing
Experiment No.
04

Title:
8051 Data Transfer Instructions

DATE:

DOC. CODE
AITS/ECD/EXPT

XCH A,R3
End

9. Copy the external code byte at address 007dh to SP.


10. Copy the internal code byte at address 02h to external RAM address 0300h.
11. Store DPTR in external RAM locations 0123h(DPL) and 02BCh(DPH).
12. Exchange both low nibbles of registers R0 and R1.
13. Store register A at the internal RAM location address in register A.
14. Copy the data on the pins of port 2 to the port 2 latch.

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

4.8

Rev. No.

1.00

Subject:
Microcontroller &
Interfacing
Experiment No.
04

Title:
8051 Data Transfer Instructions

DOC. CODE
AITS/ECD/EXPT

DATE:

Grade

Lab-In-Charge

ANSWERS
Ans.1

a) org 0000h
setb 0d4h
mov r4,#0aah
mov r5,#0aah
mov r6,#0aah
end
Uses 8 bytes of ROM
b) org 0000h
mov 14h,#0aah
mov 15h,#0aah
mov 16h,#0aah
end
Uses 9 bytes of ROM
c) org 0000h
setb 0d4h
mov a,#0aah
mov r4,a
mov r5,a
mov r6,a
end
Uses 7 bytes of ROM

Ans.2

4.8

a) org 0000h
mov 30h,#03bh
mov 31h,#03bh
mov 32h,#03bh
end
Uses 9 bytes of ROM
ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

H.O.D.

Rev. No.

1.00

Subject:
Microcontroller &
Interfacing
Experiment No.
04

Title:
8051 Data Transfer Instructions

DOC. CODE
AITS/ECD/EXPT

DATE:

b) org 0000h
mov a,#3bh
mov 31h,a
mov 32h,a
mov 30h,a
end
Uses 7 bytes of ROM
Ans.3

org 0000h
mov psw,#0abh
xch a,psw
xch a,sp
xch a,psw
end

; psw = 0aah as acc. = 00


; psw = 00h and acc. = 0aah
; sp = 0aah, psw = 01h as acc. = 07h
; psw = 07h and acc. =01h

Ans.4 org 0000h


mov 27h,#27h
mov a,27h
mov dptr,#027h
movx @dptr,a
end
Ans.5 org 0000h
mov th1,#03dh
mov tl1,#0a2h
end
Ans.6 org 0000h
mov dptr,#0123h
movx a,@dptr
mov tl0,a
mov dptr,#0234h
movx a,@dptr
mov th0,a
end
Ans.7

org 0000h
mov sp,#07h
push 81h
end
@08h = 07h

Ans.8
org 0000h
ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

4.8

Rev. No.

1.00

Subject:
Microcontroller &
Interfacing
Experiment No.
04

Title:
8051 Data Transfer Instructions

DATE:

mov r4,r3
Mov r3,r2
Mov r2,r1
Mov r1,r0
Mov r0,r4
end
Ans. 9 org 0000h
mov dptr,#7dh
movC a,@(a+dptr)
mov sp,a
end
Ans.10

org 0000h
mov dptr,#02h
mov a,#00h
movc a,@a+dptr
mov dptr,#0300h
movx @dptr,a
end

Ans.11 org 0000h


mov dptr,#12dfh
mov b,dph
mov a,dpl
mov dptr,#0123h
movx @dptr,a
mov dptr,#02bch
mov a,b
movx @dptr,a
end
Ans.12 org 0000h
mov r0,#0abh
mov r1,#35h
mov a,r0
mov r0,#01h
xchd a,@r0
mov r0,a
end
Ans.13 org 0000h
mov a,#33h
mov r0,a
mov @r0,a
ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

DOC. CODE
AITS/ECD/EXPT

4.8

Rev. No.

1.00

Subject:
Microcontroller &
Interfacing
Experiment No.
04

Title:
8051 Data Transfer Instructions

DATE:

end

Ans.14 org 0000h


mov a,p2
mov p2,a
end

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

DOC. CODE
AITS/ECD/EXPT

4.8

Rev. No.

1.00

Anda mungkin juga menyukai