XCHG

Syntax:  XCHG Rhp
Where Rhp is higher order register  the pair. ( BC or DE)
Byte: 1byte
Addressing Mode: Register Addressing
Working: for execution of this instruction, microprocessor will allocate first byte for opcode and the operand is register which don't need allocation.
After execution of this instruction content of register pair given as operand will get swapped with content of HL register pair.
Example: XCHG B
where [C]= 50H & [B] = 20 H,
[H]= 80H & [L]= 60H
(i.e. BC = 2050H and HL = 8060H)
After execution of  XCHG B
[H]= 20 H   &    [L]= 50H
[B]= 80H  &   [C]= 60H

Program: Write ALP  to swap content of BC with DE where [DE] = 4455H and
 [BC] = 1122H. 
Solution: Assume HL = 0000H
Start:  XCHG B    ;BC= 0000H & HL = 1122H
           XCHG D ; HL= 4455H& DE= 1122H
           XCHG B ; HL = 0000H & BC = 4455H
           HLT
Output: [DE] = 1122H and [BC]= 4455H

Comments

Popular posts from this blog

SBB