**Logical, Shift and Rotate Instructions of 8085:**

Logical instruction are used to perform the logical operations such as AND, OR, NOT, XOR, compare, rotate left, rotate right etc. These are described below with examples of each

**Logical Instructions:**

Name of Instruction | Mnemonic and Format | Description | Flags Affected>/td> |

Logical Compare | CMP opr | Used to Compare ACC with operand which may be in Register or memory | if A < opr: Carry Flag is set |

CPI Immidiate_opr | Used to Compare ACC with immediate operand which may be in Register or memory | if A < opr: Carry Flag is set; if A = opr: Zero Flag is set; | |

Logical And Operation | ANA opr | Used to perform logical AND operation with Register or memory | S, Z, P are modified to reflect the result of the operation. CY and AC are reset; |

ANI Immediate_opr | Used to perform logical AND operation with Register or memory | Same as above | |

Logical XOR Operation | XRA opr | Used to perform logical XOR operation with Register or memory | Same as above; |

XRI Immediate_opr | Used to perform logical XOR operation with immediate operand(Register or memory) | Same as above; | |

Logical OR Operation | ORA opr | Used to perform logical OR operation with Register or memory | Same as above; |

ORI Immediate_opr | Used to perform logical OR operation with immediate operand(Register or memory) | Same as above; | |

Logical complement Accumulator | CMA opr | Used to complement Accumulator | None; |

Complement Carry | CMC | Used to Used to complement Carry Flag | except CF No other flag affected; |

Set Carry Flag | STC | Used to Used to Set the Carry Flag | Except Carry No other flag affected; |

**2. Rotate Instructions:**

RLC: Rotate accumulator left by one position

On execution each bit is shifted to the adjacent left position. Bit D7 becomes D0. Carry flag CY is modified according to the bit D7.

RRC: Rotate accumulator right by one position

On execution each bit is shifted to the adjacent right position. Bit D7 becomes D0. Carry flag CY is modified according to the bit D0. For example

RAL: Rotate accumulator left by one position through carry flag

On executing each bit is shifted to the adjacent left position. Bit D7 becomes the carry bit and the carry bit is shifted into D0. Carry flag CY is modified according to the bit D7

RAR: Rotate accumulator rightÂ by one position through carry

On execution each bit is shifted to the adjacent right position. Bit D0 becomes the carry bit and the carry bit is shifted into D7. Carry flag CY is modified according to the bit D0

**Ex-1: Program for packing two unpacked BCD numbers stored in memory location 2000 and 2001**

We know that a BCD number is represented as group of four bits. So it is possible to pack two BCD numbers in one byte.

Suppose two numbers 5 and 6 are to be packed together.

Process:

- Load accumulator with first number from memory,
- save it to B.
- Read another number from memory in accumulator.
- Shift left four time
- OR A and B to get the packed result

Program:

LDA 2000h

MOV B, A

LDA 2001h

RLC

RLC

RLC

RLC

ORA B

STA 2002

HLT

**Ex-2: Program for unpacking a packed BCD numbers stored in memory location 2000 and save at memory location 2001 and 2002**

We know that a BCD number is represented as group of four bits. So when we read a packed BCD number from memory there will be two digit BCD number.

Process of unpacking:

- Load accumulator with number from memory,
- save it to B.
- Mask four lower bits of the number in accumulator.
- Shift right four times
- Save the number in memory
- Copy number from B into accumulator
- Mask four upper bits of the number
- Store it at next memory location

Program:

LDA 2000h

ANI 0F0h

RRC

RRC

RRC

RRC

STA 2001h

MOV A, B

ANI 0Fh

STA 2002h

HLT