Moving Data

Moving Data

Outline:

o Introduction

o Addressing Modes

o External Data Moves

o PUSH and POP Opcodes

o Data Exchanges

o Example Programs

o Summary

Introduction

A computer typically spends more time moving data from one location to another than it spends on any other operation. It is not surprising, therefore, to find that more instructions are provided for moving data than for any other type of operation.

Data is stored at a source address and moved (actually, the data is copied) to a desti­nation address. The ways by which these addresses are specified are called the addressing modes. The 8051 mnemonics are written with the destination address named first. fol­lowed by the source address.

A detailed study of the operational codes (opcodes) of the 8051 begins in this chapter.

Although there are 28 distinct mnemonics that copy data from a source to a destination, they may be divided into the following three main types:

1. MOV destination. source

2. PUSH source or POP destination

3. XCH destination, source

The following four addressing modes are used to access data:

1. Immediate addressing mode

2. Register addressing mode

3. Direct addressing mode

4. Indirect addressing mode

The MOV opcodes involve data transfers within the 8051 memory. This memory is divided into the following four distinct physical parts:

1. Internal RAM

2. Internal special-function registers

3. External RAM

4. Internal and external ROM

Finally, the following five types of opcodes are used to move data:

1. MOV

2. MOVX

3. MOVC

4. PUSH and POP

5. XCH

Addressing Modes

The way in which the data sources or destination addresses are specified in the mnemonic that moves that data determines the addressing mode. Figure 3.1 diagrams the four ad­dressing modes: immediate. register, direct. and indirect.

Immediate Addressing Mode

The simplest way to get data to a destination is to make the source of the data part of the opcode. The data source is then immediately available as part of the instruction itself.

When the 8051 executes an immediate data move, the program counter is automat­ically incremented to point to the byte(s) following the opcode byte in the program mem­ory. Whatever data is found there is copied to the destination address.

The mnemonic for immediate data is the pound sign (#). Occasionally, in the rush to meet a deadline, one forgets to use the # for immediate data. The resulting opcode is often a legal command that is assembled with no objections by the assembler. This omis­sion guarantees that the rush will continue.

Register Addressing Mode

Certain register names may be used as part of the opcode mnemonic as sources or destina­tions of data. Registers A, DPTR, and R0 to R7 may be named as part of the opcode mnemonic. Other registers in the 8051 may be addressed using the direct addressing mode. Some assemblers can equate many of the direct addresses to the register name (as is the case with the assembler discussed in this text) so that register names may be used in lieu of register addresses. Remember that the registers used in the opcode as RO to R7 are the ones that are currently chosen by the bank-select bits, RS0 and RSI in the PSW.

The following table shows all possible MOV opcodes using immediate and register addressing modes:

Mnemonic Operation

· MOV A, #n Copy the immediate data byte n to the A register

· MOV A, Rr Copy data from register Rr to register A

· MOV Rr, A Copy data from register A to register Rr

· MOV Rr, #n Copy the immediate data byte n to register Rr

· MOV DPTR, #nn Copy the immediate 16-bit number nn to the DPTR register

Addressing Modes

 

Pages-from-Hardware---The-8051-Microcontroller-Architecture,-Programming-and-Applications-1991_Page_03_Image_0001_03

 

 

A data MOV does not alter the contents of the data source address. A copy of the data is made from the source and moved to the destination address. The contents of the destina­tion address are replaced by the source address contents. The following table shows ex­amples of MOV opcodes with immediate and register addressing modes:

Mnemonic Operation

· MOV A,#0Flh Move the immediate data byte F1 h to the A register

· MOV A,R0 Copy the data in register RO to register A

· MOV DPTR,#0ABCDh Move the immediate data bytes ABCDh to the DPTR

· MOV R5,A Copy the data in register A to register R5

· MOV R3,#1Ch Move the immediate data byte I Ch to register R3

CAUTION

It is impossible to have immediate data as a destination.

All numbers must start with a decimal number (0-9), or the assembler assumes the number is a label.

Register-to-register moves using the register addressing mode occur between registers A and RO to R7.

Leave a comment

Your email address will not be published. Required fields are marked *