Texas Instruments MSC1210 User Manual

Page 220

Advertising
background image

Exchanging Register Values (XCH)

16-26

16.23 Exchanging Register Values (XCH)

Very often, the value of the accumulator will need to be swapped with the value
of another SFR or internal RAM address. The XCH instruction allows this to
be done quickly and without using additional temporary holding variables.

XCH will take the value of the accumulator and write it to the specified SFR or
internal RAM address, while at the same time writing the original value of that
SFR or internal RAM address to the accumulator.

For example:

MOV A,#25h

;accumulator now holds 25h

MOV 60h,#45h ;internal RAM 60h now holds 45h

XCH A,60h

;accumulator now holds 45, IRAM 60h now holds 25h

16.24 Swapping Accumulator Nibbles (SWAP)

In some cases, it can be useful to swap the nibbles of the accumulator. A nibble
is 4 bits, therefore, there are two nibbles in the accumulator. The high nibble
consists of bits 4 through 7, whereas the low nibble consists of bits 0 through
3.

The SWAP A instruction will swap the two nibbles of the accumulator. For ex-
ample, if the accumulator holds the value 56

H

, the SWAP instruction converts

it to 65

H

. Likewise, F7

H

is converted into 7F

H

.

Note:

The SWAP A instruction is identical to executing four RL A instructions.

16.25 Exchanging Nibbles Between Accumulator and Internal RAM (XCHD)

The XCHD instruction swaps the low nibble of the accumulator with the low
nibble of the register or internal RAM address specified in the instruction.

For example, if R0 holds 87

H

and the accumulator holds 24

H

, then the XCHD

R0 instruction results in the accumulator holding 27

H

and R0 holding 84

H

. The

low nibbles of the two are simply exchanged.

I personally have never used this instruction, but presumably it is useful in some
situations because 11 opcodes of the 8052 instruction set are devoted to it.

Advertising