Data Exchanges
Data Exchanges
MOV, PUSH, and POP opcodes all involve copying the data found in the source address to the destination address; the original data in the source is not changed. Exchange instructions actually move data in two directions: from source to destination and from destination to source. All addressing modes except immediate may be used in the XCH (exchange) opcodes:
| Mnemonic | Operation |
| XCH A,Rr | Exchange data bytes between register Rr and A |
| XCH A,add | Exchange data bytes between add and A |
| XCH A,@Rp | Exchange data bytes between A and address in Rp |
| XCHD A,@Rp | Exchange lower nibble between A and address in Rp |
Exchanges between A and any port location copy the data on the port pins to A, while the data in A is copied to the port latch. Register A is used for so many instructions that the XCH opcode provides a very convenient way to "save" the contents of A without the necessity of using a PUSH opcode and then a POP opcode.
The following table shows examples of data moves using exchange opcodes:
| Mnemonic | Operation |
| XCH A,R7 | Exchange bytes between register A and register R7 |
| XCH A,0F0h | Exchange bytes between register A and register B |
| XCH A,@R1 | Exchange bytes between register A and address in R 1 |
| XCHD A,@R1 | Exchange lower nibble in A and the address in R 1 |
CAUTION
All exchanges are internal to the 8051.
All exchanges use register A.
When using XCHD, the upper nibble of A and the upper nibble of the address location in Rp do not change.
This section concludes the listing of the various data moving instructions; the remaining sections will concentrate on using these opcodes to write short programs.
Comments
Post a Comment