Sie sind auf Seite 1von 63

Chapter 4

8051 Family Microcontrollers Instruction Set

Lesson 3

Data Transfer Instructions

Move byte between accumulator (an SFR) and register at a register bank

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

MOV Rn, A
Destination Source

Rn

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

MOV A, Rn
Destination Source

Rn

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

MOV A, Rn; MOV Rn, A


A Bank 3 Bank 2 Bank 1 Bank 0 R7 R6 R5 R4 R3 R2 R1 R0
6

Rn

8051

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

Rn
Rn: n = 0,1, 2, 3,4, 5, 6,or 7, n is as per 3 bits coexisting with 5-bits with opcode
Register n is at the bank defined by RS1 and RS0 at PSW - 00 means Bank 0, -01 bank 1 - 10 bank 2- 11 bank 3
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 7

Instruction Execution STEP 1 STEP 2 Fetch opcode-bits Fetch bits for getting the operand(s)

1 clock cycle

Time

Register addressing mode

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

Move byte from an SFR/Internal RAM to another direct

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

MOV A, direct; MOV Rn, direct; MOV direct, A; MOV direct, Rn

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

10

An SFR or Internal RAM between 00H-7FH


Destination Source

direct

A or Rn

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

11

A Bank 3 Bank 2 Bank 1 Bank 0

or

Rn

8051

Direct addressed SFR 80H-FFH or Internal RAM between 00H7FH


12

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

An SFR or Internal RAM between 00H-7FH


Destination Source

A or Rn

direct

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

13

Instruction Execution STEP 1 STEP 2 Fetch opcode-bits Fetch direct

1 clock cycle

Time

direct addressing mode

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

14

MOV direct, direct

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

15

MOV direct, direct


direct direct

8051

Direct addressed SFR or Internal RAM between 00H-7FH

Direct addressed SFR or Internal RAM between 00H-7FH


16

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

Instruction Execution STEP 1 STEP 2 STEP 3 Fetch opcode-bits Fetch direct Fetch direct

2 clock cycles

Time

both the operands using direct addressing modes

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

17

Move indirect

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

18

MOV A, @Ri; MOV @Ri, A; MOV direct, @Ri; MOV @Ri, direct

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

19

An indirect addressed Internal RAM between 00H-FFH


Destination Source

A or direct

Address pointed by R0 or R1
20

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

indirect

A or direct

8051

Indirect addressed Internal RAM between 00H-FFH

SFR direct addressed between 80H8FH or A register


21

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

An indirect Internal RAM between 00H-FFH


Destination Source

Address pointed by R0 or R1
2011

A or direct

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

22

or 4

direct R0 or R1

8051

Bank 3 Bank 2 Bank 1 Bank 0

Pointed address Internal RAM between 00HFFH


23

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

Instruction Execution
STEP 1 STEP 2 STEP 3 Fetch opcode-bits Fetch bits for A or direct Fetch bit for i 0 or 1

1 or 2 clock cycle(s)

Time

indirect addressing mode one operand 2 cycles when direct, 1 when A other operand
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 24

Instruction Execution 1. No indirect addressing in 8051 instruction for an SFR 2. Only indirect addressing in 8052 instruction Internal RAM between 80H-FFH

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

25

Move immediate, MOV immediate DPTR

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

26

byte

A register

2nd Byte of instruction

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

27

MOV A,#data Example

For moving 08H into A register MOV A, #08H

Fetch opcode and then byte for getting the operand for move

1 clock cycle Time

Sign # specifies that 08H is the immediate succeeding byte is the operand
2011

Codes in Memory74H, 08H


28

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

Rn

byte

8051

Rn (R0 or R1 or ...R6 or R7) at Bank 0 or 1or 2 or 3

2nd Byte of instruction

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

29

MOV Rn,#data Fetch opcode For moving and then byte 08H into Rn for getting the register operand for move MOV Rn, #08H Sign # specifies that 08H is the immediate succeeding byte is the operand
2011

1 clock cycle Time

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

Codes in Memory78H-7FH, 08H

30

direct

byte

8051

direct address internal RAM 00H7FH or SFR 80HFFH

2nd Byte of instruction

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

31

MOV direct,#data
For moving 08H into direct Fetch opcode and then bytes for getting the operands

2 clock cycles

Time Codes in Memory75H, 00HFFH, 08H


32

MOV direct, #08H Sign # specifies that 08H is the immediate succeeding byte is the operand
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

Destination Direct Addressing STEP 2 Fetch byte(s) after the opcode

clock cycle (s) Time

Addressing mode specifies that fetch byte(s) (next to the opcode of 8 bits) specify an address, destination operand is at that address.
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 33

indirect

byte

8051

indirect address internal RAM 00HFFH pointed by R0 or R1

2nd Byte of instruction

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

34

MOV @Ri,#data Fetch opcode For moving and then bits 08H into for getting the indirect operands MOV @Ri, #08H Sign # specifies that 08H is the immediate succeeding byte is the operand
2011

1 clock cycle Time Codes in Memory76-77H, 08H


35

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

Destination indirect Addressing STEP 2 Fetch bit 0 or 1 for R0 or R1 the opcode

1 clock cycle Time

Addressing mode specifies that fetch byte(s) specify by an address pointed by R0 or R1 at a bank
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 36

Immediate Addressing Four type of instructions

A Rn direct for Internal RAM in between


2011

00H to 7FH or direct for SFR 80HFFH Indirect using R0 or R1


Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 37

Immediate addressing mode for source two-bytes

Lower byte is second byte of the instruction and is for DPL Higher byte is third byte of the instruction and is for DPH

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

38

MOV DPTR, #data16 2 clock Fetch opcode cycles For moving and then 16 08C1H into bits for getting Time DPTR the operands MOV DPTR, #08C1H
Sign # specifies that 08C1H is two immediate succeeding bytes as the operand 2nd Ed. Raj Kamal Microcontrollers-... 2011
Pearson Education

Codes in Memory90H, C1H, 08H


39

MOVC and MOVX indirect

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

40

1. Only indirect addressing in 8051 instruction for a byte in external data memory

2. Only indirect addressing in 8051 instruction for a code in internal/external program memory
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 41

Always Indirect Addressing mode


Internal/External Program Memory (max. 64kB)

External Data Memory and Ports (max 64kB)

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

42

MOVC A, @A + PC For Fetch opcode transferring bits


addressed code byte into A
C means code memory is used

2 clock cycles Time STEPS 2-3 Code bits in Memory83H


43

MOVC A, @A + PC indirectly specify, PC16-bits adds with 8-bits at A register and then new 16-bits point to the code at that address Microcontrollers-... 2nd Ed. Raj Kamal 2011
Pearson Education

MOVC A, @A + DPTR
For transferring addressed code byte into A

2 clock cycles Time STEPS 2-3 Code bits in Memory93H

Fetch opcode bits

MOVC A, @A + DPTR

indirectly specify, DPTR16-bits adds in 8-bits at A register and then 16-bits point to code at that C means code address memory is used Microcontrollers-... 2nd Ed. Raj Kamal 44 2011
Pearson Education

MOVX A, @DPTR For Fetch opcode transferring Sign @ means an external DPTR is a byte into A pointer MOVX A, @DPTR X specifies external memory, byte at DPTR points indirectly to the address for the operand
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

2 clock cycles

Time

STEP 2
Code bits in MemoryE0H

45

MOVX @DPTR, A
For transferring A to a byte at external pointed address

Fetch opcode
Sign @ means DPTR is a pointer

2 clock cycles Time STEP 2


Code bits in MemoryF0H

MOVX @DPTR, A
X specifies external memory, byte at DPTR points indirectly to the address for the operand
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

46

MOVX A, @Ri For Fetch opcode transferring an external byte Sign @ means Ri is a pointer into A MOVX A, @Ri X specifies external memory, byte at Ri points indirectly to an external memory address for the operand
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

2 clock cycles

Time

STEP 2
Code bits in Memory- E2E3H

47

MOVX @Ri, A
For transferring Fetch opcode A to a byte at external pointed Sign @ means Ri is a pointer address MOVX @Ri, A X specifies external memory, byte at Ri points indirectly to the address for the operand
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

2 clock cycles Time

Code bits in Memory- F2F3H

48

Push or Pop direct or Exchange or Swap

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

49

Always direct Addressing mode for Push or Pop


Internal data Memory (00H-7FH) SFR (80H-FFH)

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

50

direct

4
SP

stack

1
8051 Direct address SFR or internal 007FH RAM

Increment SP Move the byte to SP pointed address 3 SP is of 8-bits

Push direct
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 51

direct
2 8051 Direct address SFR or internal 00-7FH RAM

3 SP

stack

Move the byte to SP pointed address and decrement SP 4 SP is of 8-bits

Pop direct
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 52

Instruction Execution STEP 1 STEP 2 Fetch opcode-bits Fetch byte direct

2 clock cycles

Time direct addressing mode for source operand in push and for destination operand for pop

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

53

Push an SFR or Internal RAM between 00H-7FH


Source Destination stack direct

Pre-increment SP
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 54

Pop an SFR or Internal RAM between 00H-7FH


Source Destination direct stack

Post-decrement SP
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 55

Exchange of A register byte with other


Internal data Memory (00H-FFH) SFR (80H-FFH)

A register

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

56

A 1 8051 A register

Rn or internal Temp RAM or 3 SFR

XCH A, Rn, XCH A, direct, XCH A, @Ri; exchange bytes


2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 57

Exchange of A register lower digit with other Internal data Memory (00H-FFH) SFR (80H-FFH)

A register

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

58

bit3-bit0 2 8051 Indirect address internal 00FFH RAM pointed by R0 or R1

3
temp

bit3-bit0 4 1

A register lower 4 bits XCHD A, @Ri; exchange lower digits (4-bits)

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

59

Exchange of A register lower digit with higher digit

A register lower bits

A register higher bits

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

60

bit7-bit4 1 8051 A register higher 4 bits 6

4 temp 5

bit3-bit0
2

A register lower 4 bits

SWAP A; exchange of lower digit (4bits) with higher at A


Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

2011

61

Summary

2011

Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education

62

We learnt 8051 family data transfer instructions move (copy) push pop exchange exchange lower 4-bits
2011 Microcontrollers-... 2nd Ed. Raj Kamal Pearson Education 63

Das könnte Ihnen auch gefallen