- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# 8085 program to find 1's and 2's complement of 16-bit number

In this program we will see how to find 1's complement and 2's complement of a 16-bit number.

### Problem Statement

Write 8085 Assembly language program to find 1's complement and 2's complement of a16-bit number stored in 8000H and 8001H.

### Discussion

8085 has an instruction CMA. This instruction complements the content of Accumulator. For 1's complement CMA instruction is sufficient, and for 2's complement we have to increase the number by 1 after complementing.

For 16-bit number, we are taking the number into HL pair, but for complementing we have to copy the numbers to Accumulator from H and L one by one. Then by INX instruction we will increase HL pair to get 2's complement

We are taking the number from 8000H and 8001H, and storing the 1's complement at location 8050H and 8051H, and 2's complement to 8052H and 8053H.

### Input

Address | Data |
---|---|

. . . | . . . |

8000 | CD |

8001 | AB |

. . . | . . . |

### Flow Diagram

### Program

Address | HEX Codes | Mnemonics | Comments |
---|---|---|---|

F000 | 2A, 00, 80 | LHLD 8000H | Load the number from memory to HL |

F003 | 7C | MOV A, H | Load the H content to A |

F004 | 2F | CMA | Complement the accumulator |

F005 | 67 | MOV H, A | Replace H with A |

F006 | 7D | MOV A, L | Load the L content to A |

F007 | 2F | CMA | Complement the accumulator |

F008 | 6F | MOV L, A | Replace L with A |

F009 | 22, 50, 80 | SHLD 8050H | Store the 1's complemented result |

F00C | 23 | INX H | Increase HL by 1 |

F00D | 22, 52, 80 | SHLD 8052H | Store the 2's complemented result |

F010 | 76 | HLT | Terminate the program |

### Output

Address | Data |
---|---|

. . . | . . . |

8050 | 32 |

8051 | 54 |

8052 | 33 |

8053 | 54 |

. . . | . . . |

- Related Questions & Answers
- 8085 program to find 1's and 2's complement of 8-bit number
- 1's Complement vs 2's Complement
- 1’s and 2’s complement of a Binary Number?
- 8085 program to find 2's complement of the contents of Flag Register
- 8085 program to reverse 16 bit number
- 2's complement notation
- 2's complement fractions
- 1's complement notation
- Draw a Turing machine to find 2’s complement of a binary number
- 8085 Program to Divide a 16-bit number by an 8-bit number
- Draw a Turing machine to find 1’s complement of a binary number
- Previous number same as 1’s complement in C++
- 8085 Program to convert a 16-bit binary number to BCD
- C Program to find two’s complement for a given number
- 8085 program to add two 16 bit numbers