**Q. Write an 8085 program and draw a flowchart to find 2’s complement of a 16-bit numbe**r.(8085 Microprocessor Program)

**Flowchart/Algorithm**

**Program**

Address |
Mnemonics |
Operand |
Opcode |
Comments |

2000 | LHLD | 3000H | 2A | Load H-L pair with data from 3000H. |

2001 | 00 | |||

2002 | 30 | |||

2003 | MOV | A, L | 7D | Move the lower-order from reg. L to reg. A. |

2004 | CMA | 2F | Complement accumulator. | |

2005 | MOV | L, A | 6F | Move the result from reg. A to reg. L. |

2006 | MOV | A, H | 7C | Move the higher-order from reg. H to reg. A. |

2007 | CMA | 2F | Complement accumulator. | |

2008 | MOV | H, A | 67 | Move the result from reg. A to reg. H. |

2009 | INX | H | 23 | Increment H-L pair to find 2’s complement. |

200A | SHLD | 3002H | 22 | Store the result at address 3002H. |

200B | 02 | |||

200C | 30 | |||

200D | HLT | 76 | HALT |

**Output**

*Before Execution:*

3000H: 12H

3001H: 05H

*After Execution:*

3002H: EEH

3003H: FAH

**Program Explanation**

- This program finds the 2’s complement of a 16-bit number stored in memory locations 3000H-3001H.
- There is no direct way to find 2’s complement of the 16-bit number. Therefore, this can be accomplished by finding the 1’s complement of two 8-bit numbers and then incrementing it to get 2’s complement.
- Let us assume that the operand stored at memory locations 3000H-3001H is 12H-05H.
- The operand is loaded into H-L pair from memory locations 3000H-3001H.
- The lower-order is moved from register L to accumulator.
- Its complement is found by using CMA instruction.
- The result obtained is moved back to register L.
- Then, the higher-order is moved from register H to accumulator.
- Its complement is found by using CMA instruction.
- The result obtained is moved back to register H.
- H-L pair is incremented to get 2’s complement.
- Now, the final result is in H-L pair.
- The result is stored from H-L pair to memory locations 3002H-3003H.